mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
dimension rail, part 2
This commit is contained in:
parent
21331caa1a
commit
4bcd7f9c80
5 changed files with 98 additions and 81 deletions
|
@ -1,9 +1,6 @@
|
||||||
package de.ellpeck.naturesaura.blocks;
|
package de.ellpeck.naturesaura.blocks;
|
||||||
|
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||||
import com.google.common.collect.ListMultimap;
|
|
||||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
||||||
import de.ellpeck.naturesaura.items.ItemRangeVisualizer;
|
|
||||||
import de.ellpeck.naturesaura.items.ModItems;
|
import de.ellpeck.naturesaura.items.ModItems;
|
||||||
import de.ellpeck.naturesaura.packet.PacketClient;
|
import de.ellpeck.naturesaura.packet.PacketClient;
|
||||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||||
|
@ -13,7 +10,6 @@ import de.ellpeck.naturesaura.reg.IModelProvider;
|
||||||
import de.ellpeck.naturesaura.reg.ModRegistry;
|
import de.ellpeck.naturesaura.reg.ModRegistry;
|
||||||
import net.minecraft.block.BlockRailBase;
|
import net.minecraft.block.BlockRailBase;
|
||||||
import net.minecraft.block.properties.IProperty;
|
import net.minecraft.block.properties.IProperty;
|
||||||
import net.minecraft.block.properties.PropertyBool;
|
|
||||||
import net.minecraft.block.properties.PropertyEnum;
|
import net.minecraft.block.properties.PropertyEnum;
|
||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
@ -23,40 +19,47 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.IStringSerializable;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.DimensionType;
|
import net.minecraft.world.DimensionType;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraftforge.common.DimensionManager;
|
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class BlockDimensionRail extends BlockRailBase implements IModItem, ICreativeItem, IModelProvider {
|
public class BlockDimensionRail extends BlockRailBase implements IModItem, ICreativeItem, IModelProvider {
|
||||||
|
|
||||||
public static final PropertyEnum<Type> TYPE = PropertyEnum.create("type", Type.class);
|
|
||||||
public static final PropertyEnum<EnumRailDirection> SHAPE = PropertyEnum.create("shape", EnumRailDirection.class, EnumRailDirection.NORTH_SOUTH, EnumRailDirection.EAST_WEST);
|
public static final PropertyEnum<EnumRailDirection> SHAPE = PropertyEnum.create("shape", EnumRailDirection.class, EnumRailDirection.NORTH_SOUTH, EnumRailDirection.EAST_WEST);
|
||||||
|
|
||||||
public BlockDimensionRail() {
|
private final String name;
|
||||||
|
private final int goalDim;
|
||||||
|
private final DimensionType[] canUseDims;
|
||||||
|
|
||||||
|
public BlockDimensionRail(String name, DimensionType goalDim, DimensionType... canUseDims) {
|
||||||
super(false);
|
super(false);
|
||||||
|
this.name = name;
|
||||||
|
this.goalDim = goalDim.getId();
|
||||||
|
this.canUseDims = canUseDims;
|
||||||
|
|
||||||
ModRegistry.add(this);
|
ModRegistry.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canUseHere(DimensionType dimension) {
|
||||||
|
for (DimensionType dim : this.canUseDims)
|
||||||
|
if (dim == dimension)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
||||||
ItemStack stack = playerIn.getHeldItem(hand);
|
ItemStack stack = playerIn.getHeldItem(hand);
|
||||||
if (stack.getItem() == ModItems.RANGE_VISUALIZER) {
|
if (stack.getItem() == ModItems.RANGE_VISUALIZER) {
|
||||||
if (!worldIn.isRemote) {
|
if (!worldIn.isRemote) {
|
||||||
Type type = state.getValue(TYPE);
|
BlockPos goalPos = this.getGoalCoords(worldIn, pos);
|
||||||
BlockPos goalPos = this.getGoalCoords(worldIn, pos, type);
|
|
||||||
PacketHandler.sendTo(playerIn,
|
PacketHandler.sendTo(playerIn,
|
||||||
new PacketClient(0, type.goalDim, goalPos.getX(), goalPos.getY(), goalPos.getZ()));
|
new PacketClient(0, this.goalDim, goalPos.getX(), goalPos.getY(), goalPos.getZ()));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -69,23 +72,25 @@ public class BlockDimensionRail extends BlockRailBase implements IModItem, ICrea
|
||||||
return;
|
return;
|
||||||
if (cart.isBeingRidden())
|
if (cart.isBeingRidden())
|
||||||
return;
|
return;
|
||||||
IBlockState state = world.getBlockState(pos);
|
if (!this.canUseHere(world.provider.getDimensionType()))
|
||||||
Type type = state.getValue(TYPE);
|
|
||||||
if (!type.canUseHere(world.provider.getDimensionType()))
|
|
||||||
return;
|
return;
|
||||||
BlockPos goalCoords = this.getGoalCoords(world, pos, type);
|
|
||||||
cart.changeDimension(type.goalDim, (newWorld, entity, yaw) ->
|
BlockPos goalCoords = this.getGoalCoords(world, pos);
|
||||||
|
cart.changeDimension(this.goalDim, (newWorld, entity, yaw) ->
|
||||||
entity.moveToBlockPosAndAngles(goalCoords, yaw, entity.rotationPitch));
|
entity.moveToBlockPosAndAngles(goalCoords, yaw, entity.rotationPitch));
|
||||||
|
|
||||||
|
BlockPos spot = IAuraChunk.getHighestSpot(world, pos, 35, pos);
|
||||||
|
IAuraChunk.getAuraChunk(world, spot).drainAura(spot, 50000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockPos getGoalCoords(World world, BlockPos pos, Type type) {
|
private BlockPos getGoalCoords(World world, BlockPos pos) {
|
||||||
MinecraftServer server = world.getMinecraftServer();
|
MinecraftServer server = world.getMinecraftServer();
|
||||||
if (type == Type.NETHER) {
|
if (this == ModBlocks.DIMENSION_RAIL_NETHER) {
|
||||||
// travel to the nether from the overworld
|
// travel to the nether from the overworld
|
||||||
return new BlockPos(pos.getX() / 8, pos.getY() / 2, pos.getZ() / 8);
|
return new BlockPos(pos.getX() / 8, pos.getY() / 2, pos.getZ() / 8);
|
||||||
} else if (type == Type.END) {
|
} else if (this == ModBlocks.DIMENSION_RAIL_END) {
|
||||||
// travel to the end from the overworld
|
// travel to the end from the overworld
|
||||||
WorldServer end = server.getWorld(type.goalDim);
|
WorldServer end = server.getWorld(this.goalDim);
|
||||||
return end.getSpawnCoordinate().up(8);
|
return end.getSpawnCoordinate().up(8);
|
||||||
} else {
|
} else {
|
||||||
if (world.provider.getDimensionType() == DimensionType.NETHER) {
|
if (world.provider.getDimensionType() == DimensionType.NETHER) {
|
||||||
|
@ -93,7 +98,7 @@ public class BlockDimensionRail extends BlockRailBase implements IModItem, ICrea
|
||||||
return new BlockPos(pos.getX() * 8, pos.getY() * 2, pos.getZ() * 8);
|
return new BlockPos(pos.getX() * 8, pos.getY() * 2, pos.getZ() * 8);
|
||||||
} else {
|
} else {
|
||||||
// travel to the overworld from the end
|
// travel to the overworld from the end
|
||||||
World overworld = server.getWorld(type.goalDim);
|
World overworld = server.getWorld(this.goalDim);
|
||||||
return overworld.getTopSolidOrLiquidBlock(overworld.getSpawnPoint());
|
return overworld.getTopSolidOrLiquidBlock(overworld.getSpawnPoint());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,27 +121,22 @@ public class BlockDimensionRail extends BlockRailBase implements IModItem, ICrea
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlockStateContainer createBlockState() {
|
protected BlockStateContainer createBlockState() {
|
||||||
return new BlockStateContainer(this, TYPE, SHAPE);
|
return new BlockStateContainer(this, SHAPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetaFromState(IBlockState state) {
|
public int getMetaFromState(IBlockState state) {
|
||||||
int meta = 0;
|
return state.getValue(SHAPE).getMetadata();
|
||||||
meta |= state.getValue(SHAPE).getMetadata();
|
|
||||||
meta |= state.getValue(TYPE).ordinal() << 1;
|
|
||||||
return meta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBlockState getStateFromMeta(int meta) {
|
public IBlockState getStateFromMeta(int meta) {
|
||||||
return this.getDefaultState()
|
return this.getDefaultState().withProperty(SHAPE, EnumRailDirection.byMetadata(meta));
|
||||||
.withProperty(SHAPE, EnumRailDirection.byMetadata(meta & 1))
|
|
||||||
.withProperty(TYPE, Type.values()[meta >> 1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBaseName() {
|
public String getBaseName() {
|
||||||
return "dimension_rail";
|
return "dimension_rail_" + this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -153,32 +153,4 @@ public class BlockDimensionRail extends BlockRailBase implements IModItem, ICrea
|
||||||
public void onPostInit(FMLPostInitializationEvent event) {
|
public void onPostInit(FMLPostInitializationEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Type implements IStringSerializable {
|
|
||||||
OVERWORLD("overworld", DimensionType.OVERWORLD, DimensionType.NETHER, DimensionType.THE_END),
|
|
||||||
NETHER("nether", DimensionType.NETHER, DimensionType.OVERWORLD),
|
|
||||||
END("end", DimensionType.THE_END, DimensionType.OVERWORLD);
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final int goalDim;
|
|
||||||
private final DimensionType[] canUseDims;
|
|
||||||
|
|
||||||
Type(String name, DimensionType goalDim, DimensionType... canUseDims) {
|
|
||||||
this.name = name;
|
|
||||||
this.goalDim = goalDim.getId();
|
|
||||||
this.canUseDims = canUseDims;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canUseHere(DimensionType dimension) {
|
|
||||||
for (DimensionType dim : this.canUseDims)
|
|
||||||
if (dim == dimension)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import de.ellpeck.naturesaura.ModConfig;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.SoundType;
|
import net.minecraft.block.SoundType;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.world.DimensionType;
|
||||||
|
|
||||||
public final class ModBlocks {
|
public final class ModBlocks {
|
||||||
|
|
||||||
|
@ -54,5 +55,7 @@ public final class ModBlocks {
|
||||||
public static final Block FIREWORK_GENERATOR = new BlockFireworkGenerator();
|
public static final Block FIREWORK_GENERATOR = new BlockFireworkGenerator();
|
||||||
public static final Block PROJECTILE_GENERATOR = new BlockProjectileGenerator();
|
public static final Block PROJECTILE_GENERATOR = new BlockProjectileGenerator();
|
||||||
public static final Block CHUNK_LOADER = ModConfig.enabledFeatures.chunkLoader ? new BlockChunkLoader() : null;
|
public static final Block CHUNK_LOADER = ModConfig.enabledFeatures.chunkLoader ? new BlockChunkLoader() : null;
|
||||||
public static final Block DIMENSION_RAIL = new BlockDimensionRail();
|
public static final Block DIMENSION_RAIL_OVERWORLD = new BlockDimensionRail("overworld", DimensionType.OVERWORLD, DimensionType.NETHER, DimensionType.THE_END);
|
||||||
|
public static final Block DIMENSION_RAIL_NETHER = new BlockDimensionRail("nether", DimensionType.NETHER, DimensionType.OVERWORLD);
|
||||||
|
public static final Block DIMENSION_RAIL_END = new BlockDimensionRail("end", DimensionType.THE_END, DimensionType.OVERWORLD);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"forge_marker": 1,
|
||||||
|
"defaults": {
|
||||||
|
"model": "minecraft:rail_flat",
|
||||||
|
"textures": {
|
||||||
|
"rail": "naturesaura:blocks/dimension_rail_end"
|
||||||
|
},
|
||||||
|
"transform": "forge:default-block"
|
||||||
|
},
|
||||||
|
"variants": {
|
||||||
|
"normal": [{}],
|
||||||
|
"inventory": [
|
||||||
|
{
|
||||||
|
"model": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "naturesaura:blocks/dimension_rail_end"
|
||||||
|
},
|
||||||
|
"transform": "forge:default-item"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"shape": {
|
||||||
|
"north_south": {},
|
||||||
|
"east_west": {
|
||||||
|
"y": 90
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"forge_marker": 1,
|
||||||
|
"defaults": {
|
||||||
|
"model": "minecraft:rail_flat",
|
||||||
|
"textures": {
|
||||||
|
"rail": "naturesaura:blocks/dimension_rail_nether"
|
||||||
|
},
|
||||||
|
"transform": "forge:default-block"
|
||||||
|
},
|
||||||
|
"variants": {
|
||||||
|
"normal": [{}],
|
||||||
|
"inventory": [
|
||||||
|
{
|
||||||
|
"model": "builtin/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "naturesaura:blocks/dimension_rail_nether"
|
||||||
|
},
|
||||||
|
"transform": "forge:default-item"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"shape": {
|
||||||
|
"north_south": {},
|
||||||
|
"east_west": {
|
||||||
|
"y": 90
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,9 @@
|
||||||
"forge_marker": 1,
|
"forge_marker": 1,
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"model": "minecraft:rail_flat",
|
"model": "minecraft:rail_flat",
|
||||||
|
"textures": {
|
||||||
|
"rail": "naturesaura:blocks/dimension_rail_overworld"
|
||||||
|
},
|
||||||
"transform": "forge:default-block"
|
"transform": "forge:default-block"
|
||||||
},
|
},
|
||||||
"variants": {
|
"variants": {
|
||||||
|
@ -20,23 +23,6 @@
|
||||||
"east_west": {
|
"east_west": {
|
||||||
"y": 90
|
"y": 90
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"overworld": {
|
|
||||||
"textures": {
|
|
||||||
"rail": "naturesaura:blocks/dimension_rail_overworld"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nether": {
|
|
||||||
"textures": {
|
|
||||||
"rail": "naturesaura:blocks/dimension_rail_nether"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"textures": {
|
|
||||||
"rail": "naturesaura:blocks/dimension_rail_end"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue