placement checking for multi blocks and tidying up some functions
This commit is contained in:
@@ -33,7 +33,7 @@ public class HalsSteampowered
|
|||||||
|
|
||||||
public HalsSteampowered() {
|
public HalsSteampowered() {
|
||||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
ModBlocks.BLOCKS.register(bus);
|
ModBlocks.TRACKBLOCKS.register(bus);
|
||||||
ModItems.ITEMS.register(bus);
|
ModItems.ITEMS.register(bus);
|
||||||
ModEntities.ENTITIES.register(bus);
|
ModEntities.ENTITIES.register(bus);
|
||||||
ModTileEntities.TILE_ENTITIES.register(bus);
|
ModTileEntities.TILE_ENTITIES.register(bus);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import static net.halbear.steampowered.registry.blocks.TrackClass.*;
|
|||||||
public class TrainTrack extends DirectionalBlock {
|
public class TrainTrack extends DirectionalBlock {
|
||||||
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
||||||
public static final BooleanProperty RENDER = BooleanProperty.create("render");
|
public static final BooleanProperty RENDER = BooleanProperty.create("render");
|
||||||
|
public static final BooleanProperty VALID_PLACEMENT = BooleanProperty.create("valid_placement");
|
||||||
public static final EnumProperty<TrackClass> TRACK_TYPE = EnumProperty.create("track_type", TrackClass.class);
|
public static final EnumProperty<TrackClass> TRACK_TYPE = EnumProperty.create("track_type", TrackClass.class);
|
||||||
private static final EnumProperty<TrackEnvironment> ENVIRONMENT = EnumProperty.create("environment", TrackEnvironment.class);
|
private static final EnumProperty<TrackEnvironment> ENVIRONMENT = EnumProperty.create("environment", TrackEnvironment.class);
|
||||||
private static final EnumProperty<TrackBallast> BASE = EnumProperty.create("base", TrackBallast.class);
|
private static final EnumProperty<TrackBallast> BASE = EnumProperty.create("base", TrackBallast.class);
|
||||||
@@ -99,7 +100,7 @@ public class TrainTrack extends DirectionalBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition (StateContainer.Builder<Block, BlockState> builder){
|
protected void createBlockStateDefinition (StateContainer.Builder<Block, BlockState> builder){
|
||||||
builder.add(FACING,ENVIRONMENT,BASE,TRACK_TYPE,RENDER);
|
builder.add(FACING,ENVIRONMENT,BASE,TRACK_TYPE,RENDER,VALID_PLACEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] CreateCurveOffsets(TrackClass trackType,Direction facing){
|
private static int[] CreateCurveOffsets(TrackClass trackType,Direction facing){
|
||||||
@@ -126,46 +127,89 @@ public class TrainTrack extends DirectionalBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlace(BlockState state, World world, BlockPos pos, BlockState prevState, boolean isMoving){
|
public void onPlace(BlockState state, World world, BlockPos pos, BlockState prevState, boolean isMoving){
|
||||||
super.onPlace(state, world,pos,prevState,isMoving);
|
super.onPlace(state, world, pos, prevState, isMoving);
|
||||||
|
if (!world.isClientSide()) {
|
||||||
|
boolean valid_place = true;
|
||||||
|
if (state.getValue(TRACK_TYPE) == MOUNTAININCLINE) {
|
||||||
|
Direction facing = state.getValue(FACING);
|
||||||
|
if (world.getBlockState(pos.relative(facing.getOpposite())).is(Objects.requireNonNull(BlockTags.getAllTags().getTag(new ResourceLocation("hals_steampowered", "flattrack"))))
|
||||||
|
&& world.getBlockState(pos.relative(facing)).getMaterial().isReplaceable()) {
|
||||||
|
world.setBlockAndUpdate(pos.relative(facing), ModBlocks.MOUNTAIN_INCLINE_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, MOUNTAININCLINESTART).setValue(FACING, facing).setValue(RENDER, true));
|
||||||
|
world.setBlockAndUpdate(pos, ModBlocks.MOUNTAIN_INCLINE_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, MOUNTAININCLINECHILDBOTTOM).setValue(FACING, facing).setValue(RENDER, false));
|
||||||
|
} else if (world.getBlockState(pos.relative(facing).above()).is(Objects.requireNonNull(BlockTags.getAllTags().getTag(new ResourceLocation("hals_steampowered", "flattrack"))))
|
||||||
|
&& world.getBlockState(pos.relative(facing.getOpposite())).getMaterial().isReplaceable()) {
|
||||||
|
world.setBlockAndUpdate(pos.relative(facing.getOpposite()), ModBlocks.MOUNTAIN_INCLINE_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, MOUNTAININCLINEEND).setValue(FACING, facing).setValue(RENDER, true));
|
||||||
|
world.setBlockAndUpdate(pos, ModBlocks.MOUNTAIN_INCLINE_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, MOUNTAININCLINECHILDTOP).setValue(FACING, facing).setValue(RENDER, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (state.getValue(TRACK_TYPE) == RIGHTTURNSTART && state.getValue(VALID_PLACEMENT)) {
|
||||||
|
Direction facing = state.getValue(FACING);
|
||||||
|
world.setBlockAndUpdate(pos.relative(facing).relative(facing.getClockWise()), ModBlocks.RIGHT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, RIGHTTURN).setValue(FACING, facing).setValue(RENDER, true));
|
||||||
|
world.setBlockAndUpdate(pos.relative(facing).relative(facing).relative(facing.getClockWise()).relative(facing.getClockWise()), ModBlocks.RIGHT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, RIGHTTURNEND).setValue(FACING, facing).setValue(RENDER, false));
|
||||||
|
}
|
||||||
|
if (state.getValue(TRACK_TYPE) == LEFTTURNSTART && state.getValue(VALID_PLACEMENT)) {
|
||||||
|
Direction facing = state.getValue(FACING);
|
||||||
|
world.setBlockAndUpdate(pos.relative(facing).relative(facing.getCounterClockWise()), ModBlocks.LEFT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, LEFTTURN).setValue(FACING, facing).setValue(RENDER, true));
|
||||||
|
world.setBlockAndUpdate(pos.relative(facing).relative(facing).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise()), ModBlocks.LEFT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, LEFTTURNEND).setValue(FACING, facing).setValue(RENDER, false));
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!state.getValue(VALID_PLACEMENT)) {
|
||||||
|
System.out.println(state.getBlock() +" " + "Invalid Placement" + "\nBlock Class: " + state.getValue(TRACK_TYPE));
|
||||||
|
world.destroyBlock(pos, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void onRemove(BlockState state, World world, BlockPos pos, BlockState prevState, boolean isMoving) {
|
public void onRemove(BlockState state, World world, BlockPos pos, BlockState prevState, boolean isMoving) {
|
||||||
if(state.getBlock() == ModBlocks.LEFT_TURN_TRAIN_TRACK.get()){
|
if (!world.isClientSide() && state.getValue(VALID_PLACEMENT)) {
|
||||||
Direction facing = state.getBlockState().getValue(FACING);
|
if (state.getBlock() == ModBlocks.LEFT_TURN_TRAIN_TRACK.get()) {
|
||||||
switch(state.getBlockState().getValue(TRACK_TYPE)){
|
Direction facing = state.getBlockState().getValue(FACING);
|
||||||
case LEFTTURN:
|
switch (state.getBlockState().getValue(TRACK_TYPE)) {
|
||||||
world.removeBlock(pos.relative(facing).relative(facing.getCounterClockWise()),false);
|
case LEFTTURN:
|
||||||
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getClockWise()),false);
|
world.removeBlock(pos.relative(facing).relative(facing.getCounterClockWise()), false);
|
||||||
break;
|
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getClockWise()), false);
|
||||||
case LEFTTURNEND:
|
break;
|
||||||
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getClockWise()),false);
|
case LEFTTURNEND:
|
||||||
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getOpposite()).relative(facing.getClockWise()).relative(facing.getClockWise()),false);
|
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getClockWise()), false);
|
||||||
break;
|
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getOpposite()).relative(facing.getClockWise()).relative(facing.getClockWise()), false);
|
||||||
case LEFTTURNSTART:
|
break;
|
||||||
world.removeBlock(pos.relative(facing).relative(facing.getCounterClockWise()),false);
|
case LEFTTURNSTART:
|
||||||
world.removeBlock(pos.relative(facing).relative(facing).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise()),false);
|
world.removeBlock(pos.relative(facing).relative(facing.getCounterClockWise()), false);
|
||||||
break;
|
world.removeBlock(pos.relative(facing).relative(facing).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise()), false);
|
||||||
}
|
break;
|
||||||
} else if(state.getBlock() == ModBlocks.RIGHT_TURN_TRAIN_TRACK.get()){
|
}
|
||||||
Direction facing = state.getBlockState().getValue(FACING);
|
} else if (state.getBlock() == ModBlocks.RIGHT_TURN_TRAIN_TRACK.get()) {
|
||||||
switch(state.getBlockState().getValue(TRACK_TYPE)){
|
Direction facing = state.getBlockState().getValue(FACING);
|
||||||
case RIGHTTURN:
|
switch (state.getBlockState().getValue(TRACK_TYPE)) {
|
||||||
world.removeBlock(pos.relative(facing).relative(facing.getClockWise()),false);
|
case RIGHTTURN:
|
||||||
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getCounterClockWise()),false);
|
world.removeBlock(pos.relative(facing).relative(facing.getClockWise()), false);
|
||||||
break;
|
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getCounterClockWise()), false);
|
||||||
case RIGHTTURNEND:
|
break;
|
||||||
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getCounterClockWise()),false);
|
case RIGHTTURNEND:
|
||||||
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getOpposite()).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise()),false);
|
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getCounterClockWise()), false);
|
||||||
break;
|
world.removeBlock(pos.relative(facing.getOpposite()).relative(facing.getOpposite()).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise()), false);
|
||||||
case RIGHTTURNSTART:
|
break;
|
||||||
world.removeBlock(pos.relative(facing).relative(facing.getClockWise()),false);
|
case RIGHTTURNSTART:
|
||||||
world.removeBlock(pos.relative(facing).relative(facing).relative(facing.getClockWise()).relative(facing.getClockWise()),false);
|
world.removeBlock(pos.relative(facing).relative(facing.getClockWise()), false);
|
||||||
break;
|
world.removeBlock(pos.relative(facing).relative(facing).relative(facing.getClockWise()).relative(facing.getClockWise()), false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (state.getBlock() == ModBlocks.INCLINE_TRAIN_TRACK.get()) {
|
||||||
|
Direction facing = state.getBlockState().getValue(FACING);
|
||||||
|
switch (state.getBlockState().getValue(TRACK_TYPE)) {
|
||||||
|
case MOUNTAININCLINESTART:
|
||||||
|
case MOUNTAININCLINECHILDTOP:
|
||||||
|
world.removeBlock(pos.relative(facing.getOpposite()), false);
|
||||||
|
break;
|
||||||
|
case MOUNTAININCLINEEND:
|
||||||
|
case MOUNTAININCLINECHILDBOTTOM:
|
||||||
|
world.removeBlock(pos.relative(facing), false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.onRemove(state,world,pos,prevState,isMoving);
|
super.onRemove(state,world,pos,prevState,isMoving);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,6 +229,7 @@ public class TrainTrack extends DirectionalBlock {
|
|||||||
World world = context.getLevel();
|
World world = context.getLevel();
|
||||||
Direction facing = context.getHorizontalDirection();
|
Direction facing = context.getHorizontalDirection();
|
||||||
boolean render = true;
|
boolean render = true;
|
||||||
|
boolean valid_place = true;
|
||||||
TrackEnvironment Environment;
|
TrackEnvironment Environment;
|
||||||
TrackBallast ballast;
|
TrackBallast ballast;
|
||||||
TrackClass trackType;
|
TrackClass trackType;
|
||||||
@@ -248,6 +293,14 @@ public class TrainTrack extends DirectionalBlock {
|
|||||||
case "mountainincline":
|
case "mountainincline":
|
||||||
trackType = MOUNTAININCLINE;
|
trackType = MOUNTAININCLINE;
|
||||||
break;
|
break;
|
||||||
|
case "mountaininclinechildtop":
|
||||||
|
render = false;
|
||||||
|
trackType = MOUNTAININCLINECHILDTOP;
|
||||||
|
break;
|
||||||
|
case "mountaininclinechildbottom":
|
||||||
|
render = false;
|
||||||
|
trackType = MOUNTAININCLINECHILDBOTTOM;
|
||||||
|
break;
|
||||||
case "diagonal":
|
case "diagonal":
|
||||||
trackType = DIAGONAL;
|
trackType = DIAGONAL;
|
||||||
break;
|
break;
|
||||||
@@ -260,6 +313,18 @@ public class TrainTrack extends DirectionalBlock {
|
|||||||
default:
|
default:
|
||||||
trackType = STRAIGHT;
|
trackType = STRAIGHT;
|
||||||
}
|
}
|
||||||
|
if (trackType == RIGHTTURNSTART) {
|
||||||
|
if (!world.getBlockState(placementPos.relative(facing).relative(facing.getClockWise())).getMaterial().isReplaceable() ||
|
||||||
|
!world.getBlockState(placementPos.relative(facing).relative(facing).relative(facing.getClockWise()).relative(facing.getClockWise())).getMaterial().isReplaceable()) {
|
||||||
|
valid_place = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (trackType == LEFTTURNSTART) {
|
||||||
|
if (!world.getBlockState(placementPos.relative(facing).relative(facing.getCounterClockWise())).getMaterial().isReplaceable() ||
|
||||||
|
!world.getBlockState(placementPos.relative(facing).relative(facing).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise())).getMaterial().isReplaceable()) {
|
||||||
|
valid_place = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(trackType == STRAIGHT){
|
if(trackType == STRAIGHT){
|
||||||
if (world.getBlockState(placementPos.relative(facing)).getBlock() == ModBlocks.STRAIGHT_TRAIN_TRACK.get() &&
|
if (world.getBlockState(placementPos.relative(facing)).getBlock() == ModBlocks.STRAIGHT_TRAIN_TRACK.get() &&
|
||||||
world.getBlockState(placementPos.relative(facing)).getBlockState().getValue(FACING) != facing &&
|
world.getBlockState(placementPos.relative(facing)).getBlockState().getValue(FACING) != facing &&
|
||||||
@@ -272,18 +337,6 @@ public class TrainTrack extends DirectionalBlock {
|
|||||||
world.setBlockAndUpdate(placementPos.relative(facing.getOpposite()),ModBlocks.CROSSING_TRAIN_TRACK.get().defaultBlockState());
|
world.setBlockAndUpdate(placementPos.relative(facing.getOpposite()),ModBlocks.CROSSING_TRAIN_TRACK.get().defaultBlockState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trackType == RIGHTTURNSTART) {
|
|
||||||
world.setBlockAndUpdate(placementPos.relative(facing).relative(facing.getClockWise()), ModBlocks.RIGHT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, RIGHTTURN).setValue(FACING, facing));
|
|
||||||
world.getBlockState(placementPos.relative(facing).relative(facing.getClockWise())).setValue(TRACK_TYPE, RIGHTTURN).setValue(FACING, facing).setValue(RENDER, true);
|
|
||||||
world.setBlockAndUpdate(placementPos.relative(facing).relative(facing).relative(facing.getClockWise()).relative(facing.getClockWise()), ModBlocks.RIGHT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, RIGHTTURNEND).setValue(FACING, facing));
|
|
||||||
world.getBlockState(placementPos.relative(facing).relative(facing).relative(facing.getClockWise()).relative(facing.getClockWise())).setValue(TRACK_TYPE, RIGHTTURNEND).setValue(FACING, facing).setValue(RENDER, false);
|
|
||||||
}
|
|
||||||
if (trackType == LEFTTURNSTART) {
|
|
||||||
world.setBlockAndUpdate(placementPos.relative(facing).relative(facing.getCounterClockWise()), ModBlocks.LEFT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, LEFTTURN).setValue(FACING, facing));
|
|
||||||
world.getBlockState(placementPos.relative(facing).relative(facing.getCounterClockWise())).setValue(TRACK_TYPE, LEFTTURN).setValue(FACING, facing).setValue(RENDER, true);
|
|
||||||
world.setBlockAndUpdate(placementPos.relative(facing).relative(facing).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise()), ModBlocks.LEFT_TURN_TRAIN_TRACK.get().defaultBlockState().setValue(TRACK_TYPE, LEFTTURNEND).setValue(FACING, facing));
|
|
||||||
world.getBlockState(placementPos.relative(facing).relative(facing).relative(facing.getCounterClockWise()).relative(facing.getCounterClockWise())).setValue(TRACK_TYPE, LEFTTURNEND).setValue(FACING, facing).setValue(RENDER, false);
|
|
||||||
}
|
|
||||||
if (trackType == MOUNTAININCLINE){
|
if (trackType == MOUNTAININCLINE){
|
||||||
if(world.getBlockState(placementPos.relative(facing.getOpposite()).relative(facing.getOpposite())).is(Objects.requireNonNull(BlockTags.getAllTags().getTag(new ResourceLocation("hals_steampowered", "flattrack"))))){
|
if(world.getBlockState(placementPos.relative(facing.getOpposite()).relative(facing.getOpposite())).is(Objects.requireNonNull(BlockTags.getAllTags().getTag(new ResourceLocation("hals_steampowered", "flattrack"))))){
|
||||||
trackType = MOUNTAININCLINESTART;
|
trackType = MOUNTAININCLINESTART;
|
||||||
@@ -297,6 +350,7 @@ public class TrainTrack extends DirectionalBlock {
|
|||||||
.setValue(ENVIRONMENT, Environment)
|
.setValue(ENVIRONMENT, Environment)
|
||||||
.setValue(BASE, ballast)
|
.setValue(BASE, ballast)
|
||||||
.setValue(TRACK_TYPE, trackType)
|
.setValue(TRACK_TYPE, trackType)
|
||||||
.setValue(RENDER, render);
|
.setValue(RENDER, render)
|
||||||
|
.setValue(VALID_PLACEMENT, valid_place);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,20 +15,18 @@ import net.minecraftforge.fml.RegistryObject;
|
|||||||
import net.minecraftforge.registries.DeferredRegister;
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ModBlocks {
|
public class ModBlocks {
|
||||||
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, HalsSteampowered.MODID);
|
public static final DeferredRegister<Block> TRACKBLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, HalsSteampowered.MODID);
|
||||||
|
|
||||||
|
public static ArrayList<Item> GetTrackItems(){
|
||||||
|
ArrayList<Item> trackBlocks = new ArrayList<Item>();
|
||||||
|
TRACKBLOCKS.getEntries().forEach(b -> trackBlocks.add(b.get().asItem()));
|
||||||
|
return trackBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
public static final RegistryObject<Block> STRAIGHT_TRAIN_TRACK =
|
|
||||||
registerBlock("straight_train_track",()-> new TrainTrack(AbstractBlock.Properties
|
|
||||||
.of(Material.METAL)
|
|
||||||
.strength(1.0f,1.0f)
|
|
||||||
.harvestTool(ToolType.PICKAXE)
|
|
||||||
.sound(SoundType.METAL)
|
|
||||||
.noOcclusion(),
|
|
||||||
"straight"
|
|
||||||
));
|
|
||||||
public static final RegistryObject<Block> CROSSING_TRAIN_TRACK =
|
public static final RegistryObject<Block> CROSSING_TRAIN_TRACK =
|
||||||
registerBlock("crossing_train_track",()-> new TrainTrack(AbstractBlock.Properties
|
registerBlock("crossing_train_track",()-> new TrainTrack(AbstractBlock.Properties
|
||||||
.of(Material.METAL)
|
.of(Material.METAL)
|
||||||
@@ -38,6 +36,15 @@ public class ModBlocks {
|
|||||||
.noOcclusion(),
|
.noOcclusion(),
|
||||||
"crossing"
|
"crossing"
|
||||||
));
|
));
|
||||||
|
public static final RegistryObject<Block> STRAIGHT_TRAIN_TRACK =
|
||||||
|
registerBlock("straight_train_track",()-> new TrainTrack(AbstractBlock.Properties
|
||||||
|
.of(Material.METAL)
|
||||||
|
.strength(1.0f,1.0f)
|
||||||
|
.harvestTool(ToolType.PICKAXE)
|
||||||
|
.sound(SoundType.METAL)
|
||||||
|
.noOcclusion(),
|
||||||
|
"straight"
|
||||||
|
));
|
||||||
public static final RegistryObject<Block> RIGHT_TURN_TRAIN_TRACK =
|
public static final RegistryObject<Block> RIGHT_TURN_TRAIN_TRACK =
|
||||||
registerBlock("right_turn_train_track",()-> new TrainTrack(AbstractBlock.Properties
|
registerBlock("right_turn_train_track",()-> new TrainTrack(AbstractBlock.Properties
|
||||||
.of(Material.METAL)
|
.of(Material.METAL)
|
||||||
@@ -103,7 +110,7 @@ public class ModBlocks {
|
|||||||
));
|
));
|
||||||
|
|
||||||
private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block){
|
private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block){
|
||||||
RegistryObject<T> toReturn = ModBlocks.BLOCKS.register(name, block);
|
RegistryObject<T> toReturn = ModBlocks.TRACKBLOCKS.register(name, block);
|
||||||
registerBlockItem(name, toReturn);
|
registerBlockItem(name, toReturn);
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ public enum TrackClass implements IStringSerializable {
|
|||||||
CROSSING("crossing"),
|
CROSSING("crossing"),
|
||||||
INCLINE("incline"),
|
INCLINE("incline"),
|
||||||
MOUNTAININCLINE("mountainincline"),
|
MOUNTAININCLINE("mountainincline"),
|
||||||
|
MOUNTAININCLINECHILDTOP("mountaininclinechildtop"),
|
||||||
|
MOUNTAININCLINECHILDBOTTOM("mountaininclinechildbottom"),
|
||||||
MOUNTAININCLINESTART("mountaininclinestart"),
|
MOUNTAININCLINESTART("mountaininclinestart"),
|
||||||
MOUNTAININCLINEEND("mountaininclineend"),
|
MOUNTAININCLINEEND("mountaininclineend"),
|
||||||
YJUNCTION("yjunction"),
|
YJUNCTION("yjunction"),
|
||||||
|
|||||||
@@ -13,37 +13,28 @@ import net.minecraftforge.fml.common.Mod;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.halbear.steampowered.registry.blocks.ModBlocks.GetTrackItems;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber(modid = HalsSteampowered.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
|
@Mod.EventBusSubscriber(modid = HalsSteampowered.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||||
public class ServerEventHandler {
|
public class ServerEventHandler {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void CycleTrackItem(PlayerInteractEvent.RightClickItem event){
|
public static void CycleTrackItem(PlayerInteractEvent.RightClickItem event){
|
||||||
if(!event.getWorld().isClientSide()){
|
if(!event.getWorld().isClientSide()){
|
||||||
ArrayList<Item> trackBlocks = new ArrayList<Item>();
|
ArrayList<Item> trackBlocks = GetTrackItems();
|
||||||
trackBlocks.add(ModBlocks.STRAIGHT_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.RIGHT_TURN_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.LEFT_TURN_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.RIGHT_45_DEGREE_TURN_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.LEFT_45_DEGREE_TURN_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.DIAGONAL_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.INCLINE_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.MOUNTAIN_INCLINE_TRAIN_TRACK.get().asItem());
|
|
||||||
trackBlocks.add(ModBlocks.CROSSING_TRAIN_TRACK.get().asItem());
|
|
||||||
PlayerEntity player = event.getPlayer();
|
PlayerEntity player = event.getPlayer();
|
||||||
ItemStack itemStack = event.getItemStack();
|
ItemStack itemStack = event.getItemStack();
|
||||||
int ItemCount = itemStack.getCount();
|
int ItemCount = itemStack.getCount();
|
||||||
if(trackBlocks.contains(itemStack.getItem())){
|
if(trackBlocks.contains(itemStack.getItem()) && player != null){
|
||||||
int index = trackBlocks.indexOf(itemStack.getItem());
|
int index = trackBlocks.indexOf(itemStack.getItem());
|
||||||
if(index >= trackBlocks.size() - 1){
|
if(index >= trackBlocks.size() - 1){
|
||||||
index = 0;
|
index = 0;
|
||||||
} else index++;
|
} else index++;
|
||||||
if (player != null){
|
player.setItemInHand(event.getHand(), new ItemStack(trackBlocks.get(index)));
|
||||||
player.setItemInHand(event.getHand(), new ItemStack(trackBlocks.get(index)));
|
if(event.getHand() == Hand.MAIN_HAND){
|
||||||
if(event.getHand() == Hand.MAIN_HAND){
|
player.getMainHandItem().setCount(ItemCount);
|
||||||
player.getMainHandItem().setCount(ItemCount);
|
} else{
|
||||||
} else{
|
player.getOffhandItem().setCount(ItemCount);
|
||||||
player.getOffhandItem().setCount(ItemCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,77 +1,80 @@
|
|||||||
{ "multipart": [
|
{ "multipart": [
|
||||||
{
|
{
|
||||||
"when": {"facing":"north","track_type": "mountainincline"},
|
"apply": {"model": "hals_steampowered:block/straight_track/modular/traintrack_empty_module","y": 0}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"when": {"facing":"north","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope", "y": 0}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope", "y": 0}
|
||||||
},
|
},
|
||||||
{"when": {"facing":"south","track_type": "mountainincline"},
|
{"when": {"facing":"south","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope","y": 180}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope","y": 180}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"east","track_type": "mountainincline"},
|
"when": {"facing":"east","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope","y": 90}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope","y": 90}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"west","track_type": "mountainincline"},
|
"when": {"facing":"west","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope","y": 270}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope","y": 270}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"north","track_type": "mountaininclinestart"},
|
"when": {"facing":"north","track_type": "mountaininclinestart","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition", "y": 0}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition", "y": 0}
|
||||||
},
|
},
|
||||||
{"when": {"facing":"south","track_type": "mountaininclinestart"},
|
{"when": {"facing":"south","track_type": "mountaininclinestart","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition","y": 180}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition","y": 180}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"east","track_type": "mountaininclinestart"},
|
"when": {"facing":"east","track_type": "mountaininclinestart","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition","y": 90}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition","y": 90}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"west","track_type": "mountaininclinestart"},
|
"when": {"facing":"west","track_type": "mountaininclinestart","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition","y": 270}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_starttransition","y": 270}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"north","track_type": "mountaininclineend"},
|
"when": {"facing":"north","track_type": "mountaininclineend","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition", "y": 0}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition", "y": 0}
|
||||||
},
|
},
|
||||||
{"when": {"facing":"south","track_type": "mountaininclineend"},
|
{"when": {"facing":"south","track_type": "mountaininclineend","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition","y": 180}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition","y": 180}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"east","track_type": "mountaininclineend"},
|
"when": {"facing":"east","track_type": "mountaininclineend","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition","y": 90}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition","y": 90}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"west","track_type": "mountaininclineend"},
|
"when": {"facing":"west","track_type": "mountaininclineend","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition","y": 270}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_endtransition","y": 270}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"north", "base": "ballast","track_type": "mountainincline"},
|
"when": {"facing":"north", "base": "ballast","track_type": "mountainincline","render": true},
|
||||||
"apply": {"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast", "y": 0}
|
"apply": {"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast", "y": 0}
|
||||||
},
|
},
|
||||||
{"when": {"facing":"south", "base": "ballast","track_type": "mountainincline"},
|
{"when": {"facing":"south", "base": "ballast","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast","y": 180}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast","y": 180}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"east", "base": "ballast","track_type": "mountainincline"},
|
"when": {"facing":"east", "base": "ballast","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast","y": 90}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast","y": 90}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"west", "base": "ballast","track_type": "mountainincline"},
|
"when": {"facing":"west", "base": "ballast","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast","y": 270}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_ballast","y": 270}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"north", "base": "struts","track_type": "mountainincline"},
|
"when": {"facing":"north", "base": "struts","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 0}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 0}
|
||||||
},
|
},
|
||||||
{"when": {"facing":"south", "base": "struts","track_type": "mountainincline"},
|
{"when": {"facing":"south", "base": "struts","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 180}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 180}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"east", "base": "struts","track_type": "mountainincline"},
|
"when": {"facing":"east", "base": "struts","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 90}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 90}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"when": {"facing":"west", "base": "struts","track_type": "mountainincline"},
|
"when": {"facing":"west", "base": "struts","track_type": "mountainincline","render": true},
|
||||||
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 270}
|
"apply":{"model": "hals_steampowered:block/mountainincline/traintrackgearedslope_struts","y": 270}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user