- 2
- 1
Я решил создать свой мод на Майнкрафт 1.21.7 Forge сделал уже код абсолютно весь просто прошу чтобы вы собрали его
Код на языке Toml
src/main/resources/META-INF/mods.toml
modLoader="javafml"
loaderVersion="[57,)"
license="All Rights Reserved"
[[mods]]
modId="smarthopper"
version="0.1"
displayName="Умная воронка"
description="Добавляет воронку, которая пропускает первый слот сундука"
authors="Tinter182"
Java:
package com.tinter182.smarthopper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.world.WorldlyContainer;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HopperBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.HopperBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
@Mod(SmartHopperMod.MODID)
public class SmartHopperMod {
public static final String MODID = "smarthopper";
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, MODID);
public static final RegistryObject<Block> SMART_HOPPER_BLOCK = BLOCKS.register("smart_hopper", SmartHopperBlock::new);
public static final RegistryObject<Item> SMART_HOPPER_ITEM = ITEMS.register("smart_hopper", () -> new BlockItem(SMART_HOPPER_BLOCK.get(), new Item.Properties()));
public static final RegistryObject<BlockEntityType<SmartHopperBlockEntity>> SMART_HOPPER_ENTITY = BLOCK_ENTITIES.register("smart_hopper",
() -> BlockEntityType.Builder.of(SmartHopperBlockEntity::new, SMART_HOPPER_BLOCK.get()).build(null));
public SmartHopperMod() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
BLOCKS.register(modEventBus);
ITEMS.register(modEventBus);
BLOCK_ENTITIES.register(modEventBus);
MinecraftForge.EVENT_BUS.register(this);
modEventBus.addListener(this::addCreative);
}
private void addCreative(BuildCreativeModeTabContentsEvent event) {
if (event.getTabKey() == CreativeModeTabs.FUNCTIONAL_BLOCKS) {
event.accept(SMART_HOPPER_ITEM);
}
}
}
class SmartHopperBlock extends HopperBlock {
public SmartHopperBlock(Properties properties) {
super(properties);
}
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new SmartHopperBlockEntity(pos, state);
}
}
class SmartHopperBlockEntity extends HopperBlockEntity {
public SmartHopperBlockEntity(BlockPos pos, BlockState state) {
super(pos, state);
}
@Override
public Component getDisplayName() {
return Component.translatable("block.smarthopper.smart_hopper");
}
@Override
protected boolean suckInItems() {
if (this.level == null) return false;
// Проверяем только контейнеры сверху (сундуки)
Direction direction = Direction.UP;
WorldlyContainer container = getSourceContainer(this.level, this, direction);
if (container != null && container.getClass().getName().contains("ChestBlockEntity")) {
for (int slot = 1; slot < container.getContainerSize(); slot++) { // Пропускаем первый слот
ItemStack stack = container.getItem(slot);
if (!stack.isEmpty() && canPlaceItemInContainer(container, stack, slot, direction.getOpposite())) {
ItemStack result = tryMoveInItem(this, container, stack, slot, direction);
if (!result.isEmpty()) {
return true;
}
}
}
}
return false;
}
}
`src/main/resources/assets/smarthopper/lang/ru_ru.json:
{
"block.smarthopper.smart_hopper": "Умная воронка",
"item.smarthopper.smart_hopper": "Умная воронка"
}
src/main/resources/assets/smarthopper/blockstates/smart_hopper.json:
{
"variants": {
"facing=down": {
"model": "minecraft:block/hopper"
},
"facing=east": {
"model": "minecraft:block/hopper_side"
},
"facing=north": {
"model": "minecraft:block/hopper_side"
},
"facing=south": {
"model": "minecraft:block/hopper_side"
},
"facing=west": {
"model": "minecraft:block/hopper_side"
}
}
}
src/main/resources/assets/smarthopper/models/block/smart_hopper.json:
{
"parent": "minecraft:block/hopper",
"textures": {
"particle": "minecraft:block/hopper_outside",
"top": "minecraft:block/hopper_top",
"side": "minecraft:block/hopper_side",
"inside": "minecraft:block/hopper_inside"
}
}
src/main/resources/assets/smarthopper/models/item/smart_hopper.json:
{
"parent": "minecraft:block/hopper"
}
src/main/resources/META-INF/mods.toml
modLoader="javafml"
loaderVersion="[57,)"
license="All Rights Reserved"
[[mods]]
modId="smarthopper"
version="0.1"
displayName="Умная воронка"
description="Добавляет воронку, которая пропускает первый слот сундука"
authors="Tinter182"
build.gradle:
plugins {
id 'net.minecraftforge.gradle' version '6.0.+'
id 'eclipse'
id 'maven-publish'
}
version = '0.1'
group = 'com.tinter182.smarthopper'
archivesBaseName = 'smarthopper'
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
minecraft {
mappings channel: 'official', version: '1.21.7'
runs {
client {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods {
smarthopper {
source sourceSets.main
}
}
}
}
}
dependencies {
minecraft 'net.minecraftforge:forge:1.21.7-57.0.2'
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}