Move subclass to entities
This commit is contained in:
parent
8498bfdbcf
commit
9e2d2db711
@ -10,16 +10,9 @@ import net.minecraft.world.item.Item;
|
|||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraftforge.event.RegistryEvent;
|
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.FMLClientSetupEvent;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
|
||||||
import ru.dbotthepony.mc.otm.block.*;
|
import ru.dbotthepony.mc.otm.block.*;
|
||||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityAndroidStation;
|
import ru.dbotthepony.mc.otm.block.entity.*;
|
||||||
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.item.ItemBattery;
|
import ru.dbotthepony.mc.otm.item.ItemBattery;
|
||||||
import ru.dbotthepony.mc.otm.item.ItemMatterCapacitor;
|
import ru.dbotthepony.mc.otm.item.ItemMatterCapacitor;
|
||||||
import ru.dbotthepony.mc.otm.item.ItemPill;
|
import ru.dbotthepony.mc.otm.item.ItemPill;
|
||||||
@ -154,7 +147,7 @@ public class Registry {
|
|||||||
public static BlockEntityType<BlockEntityBatteryBank> BATTERY_BANK = BlockEntityType.Builder.of(BlockEntityBatteryBank::new, Blocks.BATTERY_BANK).build(null);
|
public static BlockEntityType<BlockEntityBatteryBank> BATTERY_BANK = BlockEntityType.Builder.of(BlockEntityBatteryBank::new, Blocks.BATTERY_BANK).build(null);
|
||||||
public static BlockEntityType<BlockEntityMatterDecomposer> MATTER_DECOMPOSER = BlockEntityType.Builder.of(BlockEntityMatterDecomposer::new, Blocks.MATTER_DECOMPOSER).build(null);
|
public static BlockEntityType<BlockEntityMatterDecomposer> MATTER_DECOMPOSER = BlockEntityType.Builder.of(BlockEntityMatterDecomposer::new, Blocks.MATTER_DECOMPOSER).build(null);
|
||||||
public static BlockEntityType<BlockEntityMatterCapacitorBank> MATTER_CAPACITOR_BANK = BlockEntityType.Builder.of(BlockEntityMatterCapacitorBank::new, Blocks.MATTER_CAPACITOR_BANK).build(null);
|
public static BlockEntityType<BlockEntityMatterCapacitorBank> MATTER_CAPACITOR_BANK = BlockEntityType.Builder.of(BlockEntityMatterCapacitorBank::new, Blocks.MATTER_CAPACITOR_BANK).build(null);
|
||||||
public static BlockEntityType<BlockMatterCable.BlockEntityMatterCable> MATTER_CABLE = BlockEntityType.Builder.of(BlockMatterCable.BlockEntityMatterCable::new, Blocks.MATTER_CABLE).build(null);
|
public static BlockEntityType<BlockEntityMatterCable> MATTER_CABLE = BlockEntityType.Builder.of(BlockEntityMatterCable::new, Blocks.MATTER_CABLE).build(null);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
ANDROID_STATION.setRegistryName(Names.ANDROID_STATION);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ru.dbotthepony.mc.otm.block;
|
package ru.dbotthepony.mc.otm.block;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.mojang.math.Matrix4f;
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
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.Shapes;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
import ru.dbotthepony.mc.otm.IMatterGridCell;
|
import ru.dbotthepony.mc.otm.IMatterGridCell;
|
||||||
import ru.dbotthepony.mc.otm.MatterGrid;
|
import ru.dbotthepony.mc.otm.block.entity.BlockEntityMatterCable;
|
||||||
import ru.dbotthepony.mc.otm.Registry;
|
|
||||||
import ru.dbotthepony.mc.otm.capability.IMatterHandler;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class BlockMatterCable extends Block implements EntityBlock {
|
public class BlockMatterCable extends Block implements EntityBlock {
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -35,62 +31,6 @@ public class BlockMatterCable extends Block implements EntityBlock {
|
|||||||
return new BlockEntityMatterCable(blockPos, blockState);
|
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_SOUTH = BooleanProperty.create("connect_south");
|
||||||
public static final BooleanProperty CONNECTION_WEST = BooleanProperty.create("connect_west");
|
public static final BooleanProperty CONNECTION_WEST = BooleanProperty.create("connect_west");
|
||||||
public static final BooleanProperty CONNECTION_EAST = BooleanProperty.create("connect_east");
|
public static final BooleanProperty CONNECTION_EAST = BooleanProperty.create("connect_east");
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user