diff --git a/src/main/java/ru/dbotthepony/mc/otm/Registry.java b/src/main/java/ru/dbotthepony/mc/otm/Registry.java index 1e783d28d..d78c3a528 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/Registry.java +++ b/src/main/java/ru/dbotthepony/mc/otm/Registry.java @@ -10,16 +10,9 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import ru.dbotthepony.mc.otm.block.*; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityBatteryBank; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCapacitorBank; -import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterDecomposer; +import ru.dbotthepony.mc.otm.block.entity.*; import ru.dbotthepony.mc.otm.item.ItemBattery; import ru.dbotthepony.mc.otm.item.ItemMatterCapacitor; import ru.dbotthepony.mc.otm.item.ItemPill; @@ -154,7 +147,7 @@ public class Registry { public static BlockEntityType BATTERY_BANK = BlockEntityType.Builder.of(BlockEntityBatteryBank::new, Blocks.BATTERY_BANK).build(null); public static BlockEntityType MATTER_DECOMPOSER = BlockEntityType.Builder.of(BlockEntityMatterDecomposer::new, Blocks.MATTER_DECOMPOSER).build(null); public static BlockEntityType MATTER_CAPACITOR_BANK = BlockEntityType.Builder.of(BlockEntityMatterCapacitorBank::new, Blocks.MATTER_CAPACITOR_BANK).build(null); - public static BlockEntityType MATTER_CABLE = BlockEntityType.Builder.of(BlockMatterCable.BlockEntityMatterCable::new, Blocks.MATTER_CABLE).build(null); + public static BlockEntityType MATTER_CABLE = BlockEntityType.Builder.of(BlockEntityMatterCable::new, Blocks.MATTER_CABLE).build(null); static { ANDROID_STATION.setRegistryName(Names.ANDROID_STATION); diff --git a/src/main/java/ru/dbotthepony/mc/otm/block/BlockMatterCable.java b/src/main/java/ru/dbotthepony/mc/otm/block/BlockMatterCable.java index 1b4db5cfb..75a96de80 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/block/BlockMatterCable.java +++ b/src/main/java/ru/dbotthepony/mc/otm/block/BlockMatterCable.java @@ -1,7 +1,6 @@ package ru.dbotthepony.mc.otm.block; import com.google.common.collect.ImmutableMap; -import com.mojang.math.Matrix4f; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.BlockGetter; @@ -20,13 +19,10 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import ru.dbotthepony.mc.otm.IMatterGridCell; -import ru.dbotthepony.mc.otm.MatterGrid; -import ru.dbotthepony.mc.otm.Registry; -import ru.dbotthepony.mc.otm.capability.IMatterHandler; +import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCable; import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.HashMap; public class BlockMatterCable extends Block implements EntityBlock { @Nullable @@ -35,62 +31,6 @@ public class BlockMatterCable extends Block implements EntityBlock { return new BlockEntityMatterCable(blockPos, blockState); } - public static class BlockEntityMatterCable extends BlockEntity implements IMatterGridCell { - public BlockEntityMatterCable(BlockPos p_155229_, BlockState p_155230_) { - super(Registry.BlockEntities.MATTER_CABLE, p_155229_, p_155230_); - // OverdriveThatMatters.LOGGER.debug("create cable block entity {} {} {}", this, p_155229_, p_155230_); - } - - private MatterGrid grid; - - @Override - public void setLevel(Level p_155231_) { - super.setLevel(p_155231_); - - if (grid == null) - MatterGrid.scheduleDiscoverNeighbours(this, getBlockPos(), p_155231_); - } - - @Override - public void onNeighbourMatterCell(BlockPos pos, Level level, Direction direction, IMatterGridCell cell) { - // OverdriveThatMatters.LOGGER.debug("Try to connect cable entity {} {} to {} {} ({})", this, pos, pos.offset(direction.getNormal()), direction, cell); - BlockState new_state = getBlockState().setValue(MAPPING_CONNECTION_PROP[direction.ordinal()], true); - - if (new_state != getBlockState()) - level.setBlock(getBlockPos(), new_state, UPDATE_CLIENTS); - } - - @Override - public void setRemoved() { - super.setRemoved(); - - if (grid != null) - grid.untrack(this); - } - - @Nullable - @Override - public MatterGrid getMatterGrid() { - return grid; - } - - @Nullable - @Override - public IMatterHandler getMatterHandler() { - return null; - } - - @Override - public boolean isValidMatterCell() { - return !isRemoved(); - } - - @Override - public void setMatterGrid(MatterGrid grid) { - this.grid = grid; - } - } - public static final BooleanProperty CONNECTION_SOUTH = BooleanProperty.create("connect_south"); public static final BooleanProperty CONNECTION_WEST = BooleanProperty.create("connect_west"); public static final BooleanProperty CONNECTION_EAST = BooleanProperty.create("connect_east"); diff --git a/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCable.java b/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCable.java new file mode 100644 index 000000000..28a4ea603 --- /dev/null +++ b/src/main/java/ru/dbotthepony/mc/otm/block/entity/BlockEntityMatterCable.java @@ -0,0 +1,71 @@ +package ru.dbotthepony.mc.otm.block.entity; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import ru.dbotthepony.mc.otm.IMatterGridCell; +import ru.dbotthepony.mc.otm.MatterGrid; +import ru.dbotthepony.mc.otm.Registry; +import ru.dbotthepony.mc.otm.block.BlockMatterCable; +import ru.dbotthepony.mc.otm.capability.IMatterHandler; + +import javax.annotation.Nullable; + +public class BlockEntityMatterCable extends BlockEntity implements IMatterGridCell { + public BlockEntityMatterCable(BlockPos p_155229_, BlockState p_155230_) { + super(Registry.BlockEntities.MATTER_CABLE, p_155229_, p_155230_); + // OverdriveThatMatters.LOGGER.debug("create cable block entity {} {} {}", this, p_155229_, p_155230_); + } + + private MatterGrid grid; + + @Override + public void setLevel(Level p_155231_) { + super.setLevel(p_155231_); + + if (grid == null) + MatterGrid.scheduleDiscoverNeighbours(this, getBlockPos(), p_155231_); + } + + @Override + public void onNeighbourMatterCell(BlockPos pos, Level level, Direction direction, IMatterGridCell cell) { + // OverdriveThatMatters.LOGGER.debug("Try to connect cable entity {} {} to {} {} ({})", this, pos, pos.offset(direction.getNormal()), direction, cell); + BlockState new_state = getBlockState().setValue(BlockMatterCable.MAPPING_CONNECTION_PROP[direction.ordinal()], true); + + if (new_state != getBlockState()) + level.setBlock(getBlockPos(), new_state, Block.UPDATE_CLIENTS); + } + + @Override + public void setRemoved() { + super.setRemoved(); + + if (grid != null) + grid.untrack(this); + } + + @Nullable + @Override + public MatterGrid getMatterGrid() { + return grid; + } + + @Nullable + @Override + public IMatterHandler getMatterHandler() { + return null; + } + + @Override + public boolean isValidMatterCell() { + return !isRemoved(); + } + + @Override + public void setMatterGrid(MatterGrid grid) { + this.grid = grid; + } +}