diff --git a/gradle.properties b/gradle.properties index df17dfa..5a9fc86 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,5 +3,5 @@ org.gradle.jvmargs=-Xmx4G mc_version=1.11.2 forge_version=1.11.2-13.20.1.2530 -mod_version=1.2 +mod_version=1.3 mappings_version=stable_32 diff --git a/src/main/java/jackyy/dimensionaledibles/DimensionalEdibles.java b/src/main/java/jackyy/dimensionaledibles/DimensionalEdibles.java index b1fa005..b089469 100644 --- a/src/main/java/jackyy/dimensionaledibles/DimensionalEdibles.java +++ b/src/main/java/jackyy/dimensionaledibles/DimensionalEdibles.java @@ -16,7 +16,7 @@ @Mod(modid = DimensionalEdibles.MODID, name = DimensionalEdibles.MODNAME, version = DimensionalEdibles.VERSION, acceptedMinecraftVersions = DimensionalEdibles.MCVERSION, dependencies = DimensionalEdibles.DEPENDS, certificateFingerprint = "@FINGERPRINT@", useMetadata = true) public class DimensionalEdibles { - public static final String VERSION = "1.2"; + public static final String VERSION = "1.3"; public static final String MCVERSION = "[1.11,1.12)"; public static final String MODID = "dimensionaledibles"; public static final String MODNAME = "Dimensional Edibles"; diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockCakeBase.java b/src/main/java/jackyy/dimensionaledibles/block/BlockCakeBase.java index 06d9195..a383631 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockCakeBase.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockCakeBase.java @@ -31,18 +31,17 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import javax.annotation.Nullable; import java.util.List; import java.util.Random; /** - * This is based on the vanilla cake class, - * but slightly modified and added Waila / TOP support. + * This is based on the vanilla cake class, but slightly modified and added + * Waila / TOP support. */ public class BlockCakeBase extends Block implements ITOPInfoProvider, IWailaInfoProvider { public static final PropertyInteger BITES = PropertyInteger.create("bites", 0, 6); - public static final AxisAlignedBB[] CAKE_AABB = new AxisAlignedBB[] {new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.1875D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.3125D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.4375D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.5625D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.6875D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.8125D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D)}; + public static final AxisAlignedBB[] CAKE_AABB = new AxisAlignedBB[]{new AxisAlignedBB(0.0625D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.1875D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.3125D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.4375D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.5625D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.6875D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D), new AxisAlignedBB(0.8125D, 0.0D, 0.0625D, 0.9375D, 0.5D, 0.9375D)}; public BlockCakeBase() { super(Material.CAKE); @@ -53,22 +52,22 @@ public BlockCakeBase() { setCreativeTab(DimensionalEdibles.TAB); } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return CAKE_AABB[state.getValue(BITES)]; } - @Override @SideOnly(Side.CLIENT) @SuppressWarnings("deprecation") + @Override @SideOnly(Side.CLIENT) @Deprecated public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos) { return state.getCollisionBoundingBox(worldIn, pos); } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public boolean isFullCube(IBlockState state) { return false; } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public boolean isOpaqueCube(IBlockState state) { return false; } @@ -79,11 +78,9 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, playerIn.addStat(StatList.CAKE_SLICES_EATEN); playerIn.getFoodStats().addStats(2, 0.1F); int i = state.getValue(BITES); - if (i < 6) { worldIn.setBlockState(pos, state.withProperty(BITES, i + 1), 3); - } - else { + } else { worldIn.setBlockToAir(pos); } } @@ -95,7 +92,7 @@ public boolean canPlaceBlockAt(World worldIn, BlockPos pos) { return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos); } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { if (!this.canBlockStay(worldIn, pos)) { worldIn.setBlockToAir(pos); @@ -111,12 +108,12 @@ public int quantityDropped(Random random) { return 0; } - @Override @Nullable + @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return null; } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(BITES, meta); } @@ -136,12 +133,12 @@ protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, BITES); } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { return (7 - blockState.getValue(BITES)) * 2; } - @Override @SuppressWarnings("deprecation") + @Override @Deprecated public boolean hasComparatorInputOverride(IBlockState state) { return true; } diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java new file mode 100644 index 0000000..3b3039b --- /dev/null +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java @@ -0,0 +1,146 @@ +package jackyy.dimensionaledibles.block; + +import jackyy.dimensionaledibles.DimensionalEdibles; +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; +import jackyy.dimensionaledibles.registry.ModConfig; +import jackyy.dimensionaledibles.util.TeleporterHandler; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.state.IBlockState; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.logging.log4j.Level; + +import javax.annotation.Nonnull; + +public class BlockCustomCake extends BlockCakeBase implements ITileEntityProvider { + + public BlockCustomCake() { + super(); + setRegistryName(DimensionalEdibles.MODID + ":custom_cake"); + setUnlocalizedName(DimensionalEdibles.MODID + ".custom_cake"); + } + + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { + int meta = getMetaFromState(world.getBlockState(pos)) - 1; + ItemStack stack = player.getHeldItem(hand); + int dimension = 0; + TileEntity ent = world.getTileEntity(pos); + if (ent != null && ent instanceof TileDimensionCake) { + dimension = ((TileDimensionCake) ent).getDimensionID(); + } + String fuel = "minecraft:air"; + for (String s : ModConfig.tweaks.customEdible.customCake.fuel) { + try { + String[] parts = s.split(","); + if (parts.length < 2) { + DimensionalEdibles.logger.log(Level.ERROR, s + " is not a valid input line! Format needs to be: , "); + continue; + } + if (Integer.parseInt(parts[0].trim()) == dimension) { + fuel = parts[1].trim(); + } + } catch (NumberFormatException e) { + DimensionalEdibles.logger.log(Level.ERROR, s + " is not a valid line input! The dimension ID needs to be a number!"); + } + } + if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(fuel))) { + if (meta >= 0) { + world.setBlockState(pos, state.withProperty(BITES, meta), 2); + if (!player.capabilities.isCreativeMode) { + stack.shrink(1); + } + return true; + } + } else { + if (world.provider.getDimension() != dimension) { + if (!world.isRemote) { + if (player.capabilities.isCreativeMode) { + teleportPlayer(world, player, dimension); + } else { + consumeCake(world, pos, player, dimension); + } + return true; + } + } + } + return false; + } + + private void teleportPlayer(World world, EntityPlayer player, int dimension) { + EntityPlayerMP playerMP = (EntityPlayerMP) player; + BlockPos coords = TeleporterHandler.getDimPos(playerMP, dimension, player.getPosition()); + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); + TeleporterHandler.teleport(playerMP, dimension, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + } + + private void consumeCake(World world, BlockPos pos, EntityPlayer player, int dimension) { + if (player.canEat(true)) { + int l = world.getBlockState(pos).getValue(BITES); + if (l < 6) { + player.getFoodStats().addStats(2, 0.1F); + world.setBlockState(pos, world.getBlockState(pos).withProperty(BITES, l + 1), 3); + teleportPlayer(world, player, dimension); + } + } + } + + @Override + public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { + return ModConfig.tweaks.customEdible.customCake.preFueled ? getDefaultState().withProperty(BITES, 0) : getDefaultState().withProperty(BITES, 6); + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(@Nonnull Item item, CreativeTabs tab, NonNullList list) { + if (ModConfig.general.customCake) { + ItemStack stack; + for (String s : ModConfig.tweaks.customEdible.dimensions) { + try { + String[] parts = s.split(","); + if (parts.length < 2) { + DimensionalEdibles.logger.log(Level.ERROR, s + " is not a valid input line! Format needs to be: , "); + continue; + } + int dimension = Integer.parseInt(parts[0].trim()); + if (DimensionManager.isDimensionRegistered(dimension)) { + stack = new ItemStack(this); + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + nbt = new NBTTagCompound(); + stack.setTagCompound(nbt); + } + nbt.setInteger("dimID", dimension); + nbt.setString("cakeName", parts[1].trim()); + list.add(stack); + } else { + DimensionalEdibles.logger.log(Level.ERROR, parts[0] + " is not a valid dimension ID! (Needs to be a number)"); + } + } catch (NumberFormatException e) { + DimensionalEdibles.logger.log(Level.ERROR, s + " is not a valid line input! The dimension ID needs to be a number!"); + } + } + } + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileDimensionCake(); + } + +} diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockEndCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockEndCake.java index ec656a8..68f6a3f 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockEndCake.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockEndCake.java @@ -1,17 +1,18 @@ package jackyy.dimensionaledibles.block; import jackyy.dimensionaledibles.DimensionalEdibles; +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; import jackyy.dimensionaledibles.registry.ModConfig; import jackyy.dimensionaledibles.util.TeleporterHandler; +import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.MobEffects; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.potion.PotionEffect; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; @@ -23,7 +24,7 @@ import javax.annotation.Nonnull; -public class BlockEndCake extends BlockCakeBase { +public class BlockEndCake extends BlockCakeBase implements ITileEntityProvider { public BlockEndCake() { super(); @@ -35,77 +36,67 @@ public BlockEndCake() { public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { int meta = getMetaFromState(world.getBlockState(pos)) - 1; ItemStack stack = player.getHeldItem(hand); - - if (player.capabilities.isCreativeMode) { - if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.endCake.fuel))) { - world.setBlockState(pos, getStateFromMeta(0), 2); - return true; - } - else { - if (world.provider.getDimension() != 1) { - if (!world.isRemote) { - if (ModConfig.tweaks.endCake.useCustomCoords) { - EntityPlayerMP playerMP = (EntityPlayerMP) player; - BlockPos coords = new BlockPos(ModConfig.tweaks.endCake.customCoords.x, ModConfig.tweaks.endCake.customCoords.y, ModConfig.tweaks.endCake.customCoords.z); - TeleporterHandler.teleport(playerMP, 1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); - } else { - player.changeDimension(1); - } - return true; - } - } - } - } - else { - if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.endCake.fuel))) { - if (meta >= 0) { - world.setBlockState(pos, getStateFromMeta(meta), 2); + if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.endCake.fuel))) { + if (meta >= 0) { + world.setBlockState(pos, state.withProperty(BITES, meta), 2); + if (!player.capabilities.isCreativeMode) { stack.shrink(1); - return true; } + return true; } - else { - if (world.provider.getDimension() != 1) { - if (!world.isRemote) { + } else { + if (world.provider.getDimension() != 1) { + if (!world.isRemote) { + if (player.capabilities.isCreativeMode) { + teleportPlayer(world, player); + } else { consumeCake(world, pos, player); - return true; } + return true; } } } - return false; } + private void teleportPlayer(World world, EntityPlayer player) { + EntityPlayerMP playerMP = (EntityPlayerMP) player; + BlockPos coords; + if (ModConfig.tweaks.endCake.useCustomCoords) { + coords = new BlockPos(ModConfig.tweaks.endCake.customCoords.x, ModConfig.tweaks.endCake.customCoords.y, ModConfig.tweaks.endCake.customCoords.z); + } else { + coords = TeleporterHandler.getDimPos(playerMP, 1, player.getPosition()); + } + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); + TeleporterHandler.teleport(playerMP, 1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + } + private void consumeCake(World world, BlockPos pos, EntityPlayer player) { if (player.canEat(true)) { int l = world.getBlockState(pos).getValue(BITES); - if (l < 6) { player.getFoodStats().addStats(2, 0.1F); world.setBlockState(pos, world.getBlockState(pos).withProperty(BITES, l + 1), 3); - if (ModConfig.tweaks.endCake.useCustomCoords) { - EntityPlayerMP playerMP = (EntityPlayerMP) player; - BlockPos coords = new BlockPos(ModConfig.tweaks.endCake.customCoords.x, ModConfig.tweaks.endCake.customCoords.y, ModConfig.tweaks.endCake.customCoords.z); - TeleporterHandler.teleport(playerMP, 1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); - } else { - player.changeDimension(1); - player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 200, 200, false, false)); - } + teleportPlayer(world, player); } } } - @Override @SuppressWarnings("deprecation") - public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { - return ModConfig.tweaks.endCake.preFueled ? getStateFromMeta(0) : getStateFromMeta(6); + @Override + public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { + return ModConfig.tweaks.endCake.preFueled ? getDefaultState().withProperty(BITES, 0) : getDefaultState().withProperty(BITES, 6); } @Override @SideOnly(Side.CLIENT) public void getSubBlocks(@Nonnull Item item, CreativeTabs tab, NonNullList list) { if (ModConfig.general.endCake) - list.add(new ItemStack(item)); + list.add(new ItemStack(this)); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) { + return new TileDimensionCake(1, "End"); } } diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockNetherCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockNetherCake.java index d15e0e2..c9a7f77 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockNetherCake.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockNetherCake.java @@ -1,8 +1,10 @@ package jackyy.dimensionaledibles.block; import jackyy.dimensionaledibles.DimensionalEdibles; +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; import jackyy.dimensionaledibles.registry.ModConfig; import jackyy.dimensionaledibles.util.TeleporterHandler; +import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; @@ -10,6 +12,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; @@ -21,7 +24,7 @@ import javax.annotation.Nonnull; -public class BlockNetherCake extends BlockCakeBase { +public class BlockNetherCake extends BlockCakeBase implements ITileEntityProvider { public BlockNetherCake() { super(); @@ -33,78 +36,67 @@ public BlockNetherCake() { public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { int meta = getMetaFromState(world.getBlockState(pos)) - 1; ItemStack stack = player.getHeldItem(hand); - - if (player.capabilities.isCreativeMode) { - if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.netherCake.fuel))) { - world.setBlockState(pos, getStateFromMeta(0), 2); - return true; - } - else { - if (world.provider.getDimension() != -1) { - if (!world.isRemote) { - EntityPlayerMP playerMP = (EntityPlayerMP) player; - BlockPos coords; - if (ModConfig.tweaks.netherCake.useCustomCoords) { - coords = new BlockPos(ModConfig.tweaks.netherCake.customCoords.x, ModConfig.tweaks.netherCake.customCoords.y, ModConfig.tweaks.netherCake.customCoords.z); - } else { - coords = new BlockPos(0, world.getSeaLevel() + 1, 0); - } - TeleporterHandler.teleport(playerMP, -1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); - } - } - return true; - } - } - else { - if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.netherCake.fuel))) { - if (meta >= 0) { - world.setBlockState(pos, getStateFromMeta(meta), 2); + if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.netherCake.fuel))) { + if (meta >= 0) { + world.setBlockState(pos, state.withProperty(BITES, meta), 2); + if (!player.capabilities.isCreativeMode) { stack.shrink(1); - return true; } + return true; } - else { - if (world.provider.getDimension() != -1) { - if (!world.isRemote) { + } else { + if (world.provider.getDimension() != -1) { + if (!world.isRemote) { + if (player.capabilities.isCreativeMode) { + teleportPlayer(world, player); + } else { consumeCake(world, pos, player); - return true; } + return true; } } } - return false; } + private void teleportPlayer(World world, EntityPlayer player) { + EntityPlayerMP playerMP = (EntityPlayerMP) player; + BlockPos coords; + if (ModConfig.tweaks.netherCake.useCustomCoords) { + coords = new BlockPos(ModConfig.tweaks.netherCake.customCoords.x, ModConfig.tweaks.netherCake.customCoords.y, ModConfig.tweaks.netherCake.customCoords.z); + } else { + coords = TeleporterHandler.getDimPos(playerMP, -1, player.getPosition()); + } + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); + TeleporterHandler.teleport(playerMP, -1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + } + private void consumeCake(World world, BlockPos pos, EntityPlayer player) { if (player.canEat(true)) { int l = world.getBlockState(pos).getValue(BITES); - if (l < 6) { player.getFoodStats().addStats(2, 0.1F); world.setBlockState(pos, world.getBlockState(pos).withProperty(BITES, l + 1), 3); - EntityPlayerMP playerMP = (EntityPlayerMP) player; - BlockPos coords; - if (ModConfig.tweaks.netherCake.useCustomCoords) { - coords = new BlockPos(ModConfig.tweaks.netherCake.customCoords.x, ModConfig.tweaks.netherCake.customCoords.y, ModConfig.tweaks.netherCake.customCoords.z); - } else { - coords = new BlockPos(0, world.getSeaLevel() + 1, 0); - } - TeleporterHandler.teleport(playerMP, -1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + teleportPlayer(world, player); } } } - @Override @SuppressWarnings("deprecation") - public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { - return ModConfig.tweaks.netherCake.preFueled ? getStateFromMeta(0) : getStateFromMeta(6); + @Override + public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { + return ModConfig.tweaks.netherCake.preFueled ? getDefaultState().withProperty(BITES, 0) : getDefaultState().withProperty(BITES, 6); } @Override @SideOnly(Side.CLIENT) public void getSubBlocks(@Nonnull Item item, CreativeTabs tab, NonNullList list) { if (ModConfig.general.netherCake) - list.add(new ItemStack(item)); + list.add(new ItemStack(this)); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) { + return new TileDimensionCake(-1, "Nether"); } } diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockOverworldCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockOverworldCake.java index 2bc0d57..ed15b7f 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockOverworldCake.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockOverworldCake.java @@ -1,8 +1,10 @@ package jackyy.dimensionaledibles.block; import jackyy.dimensionaledibles.DimensionalEdibles; +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; import jackyy.dimensionaledibles.registry.ModConfig; import jackyy.dimensionaledibles.util.TeleporterHandler; +import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; @@ -10,6 +12,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.NonNullList; @@ -21,7 +24,7 @@ import javax.annotation.Nonnull; -public class BlockOverworldCake extends BlockCakeBase { +public class BlockOverworldCake extends BlockCakeBase implements ITileEntityProvider { public BlockOverworldCake() { super(); @@ -33,84 +36,67 @@ public BlockOverworldCake() { public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { int meta = getMetaFromState(world.getBlockState(pos)) - 1; ItemStack stack = player.getHeldItem(hand); - - if (player.capabilities.isCreativeMode) { - if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.overworldCake.fuel))) { - world.setBlockState(pos, getStateFromMeta(0), 2); - return true; - } - else { - if (world.provider.getDimension() != 0) { - if (!world.isRemote) { - EntityPlayerMP playerMP = (EntityPlayerMP) player; - BlockPos coords; - if (ModConfig.tweaks.overworldCake.useCustomCoords) { - coords = new BlockPos(ModConfig.tweaks.overworldCake.customCoords.x, ModConfig.tweaks.overworldCake.customCoords.y, ModConfig.tweaks.overworldCake.customCoords.z); - } else { - coords = world.getSpawnPoint(); - while (world.getBlockState(world.getSpawnPoint()).isFullCube()) { - coords = coords.up(2); - } - } - TeleporterHandler.teleport(playerMP, 0, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); - } - } - return true; - } - } - else { - if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.overworldCake.fuel))) { - if (meta >= 0) { - world.setBlockState(pos, getStateFromMeta(meta), 2); + if (!stack.isEmpty() && stack.getItem() == Item.REGISTRY.getObject(new ResourceLocation(ModConfig.tweaks.overworldCake.fuel))) { + if (meta >= 0) { + world.setBlockState(pos, state.withProperty(BITES, meta), 2); + if (!player.capabilities.isCreativeMode) { stack.shrink(1); - return true; } + return true; } - else { - if (world.provider.getDimension() != 0) { - if (!world.isRemote) { + } else { + if (world.provider.getDimension() != 0) { + if (!world.isRemote) { + if (player.capabilities.isCreativeMode) { + teleportPlayer(world, player); + } else { consumeCake(world, pos, player); - return true; } + return true; } } } - return false; } + private void teleportPlayer(World world, EntityPlayer player) { + EntityPlayerMP playerMP = (EntityPlayerMP) player; + BlockPos coords; + if (ModConfig.tweaks.overworldCake.useCustomCoords) { + coords = new BlockPos(ModConfig.tweaks.overworldCake.customCoords.x, ModConfig.tweaks.overworldCake.customCoords.y, ModConfig.tweaks.overworldCake.customCoords.z); + } else { + coords = TeleporterHandler.getDimPos(playerMP, 0, player.getPosition()); + } + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); + TeleporterHandler.teleport(playerMP, 0, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + } + private void consumeCake(World world, BlockPos pos, EntityPlayer player) { if (player.canEat(true)) { int l = world.getBlockState(pos).getValue(BITES); - if (l < 6) { player.getFoodStats().addStats(2, 0.1F); world.setBlockState(pos, world.getBlockState(pos).withProperty(BITES, l + 1), 3); - EntityPlayerMP playerMP = (EntityPlayerMP) player; - BlockPos coords; - if (ModConfig.tweaks.overworldCake.useCustomCoords) { - coords = new BlockPos(ModConfig.tweaks.overworldCake.customCoords.x, ModConfig.tweaks.overworldCake.customCoords.y, ModConfig.tweaks.overworldCake.customCoords.z); - } else { - coords = world.getSpawnPoint(); - while (world.getBlockState(world.getSpawnPoint()).isFullCube()) { - coords = coords.up(2); - } - } - TeleporterHandler.teleport(playerMP, 0, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + teleportPlayer(world, player); } } } - @Override @SuppressWarnings("deprecation") - public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { - return ModConfig.tweaks.overworldCake.preFueled ? getStateFromMeta(0) : getStateFromMeta(6); + @Override + public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { + return ModConfig.tweaks.overworldCake.preFueled ? getDefaultState().withProperty(BITES, 0) : getDefaultState().withProperty(BITES, 6); } @Override @SideOnly(Side.CLIENT) public void getSubBlocks(@Nonnull Item item, CreativeTabs tab, NonNullList list) { if (ModConfig.general.overworldCake) - list.add(new ItemStack(item)); + list.add(new ItemStack(this)); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta) { + return new TileDimensionCake(0, "Overworld"); } } diff --git a/src/main/java/jackyy/dimensionaledibles/block/tile/TileDimensionCake.java b/src/main/java/jackyy/dimensionaledibles/block/tile/TileDimensionCake.java new file mode 100644 index 0000000..46f1f6a --- /dev/null +++ b/src/main/java/jackyy/dimensionaledibles/block/tile/TileDimensionCake.java @@ -0,0 +1,76 @@ +package jackyy.dimensionaledibles.block.tile; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class TileDimensionCake extends TileEntity { + + private int dimensionID; + private String cakeName; + + public TileDimensionCake() { + this(0, "Overworld"); + } + + public TileDimensionCake(int dimID, String name) { + this.dimensionID = dimID; + this.cakeName = name; + } + + public int getDimensionID() { + return this.dimensionID; + } + + public void setDimensionID(int dimID) { + this.dimensionID = dimID; + } + + public String getCakeName() { + return this.cakeName; + } + + public void setCakeName(String name) { + this.cakeName = name; + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setInteger("dimID", this.getDimensionID()); + nbt.setString("cakeName", this.getCakeName()); + return nbt; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.dimensionID = nbt.getInteger("dimID"); + this.cakeName = nbt.getString("cakeName"); + } + + @Override + public SPacketUpdateTileEntity getUpdatePacket() { + return new SPacketUpdateTileEntity(this.pos, 1, this.getUpdateTag()); + } + + @Override + public NBTTagCompound getUpdateTag() { + return this.writeToNBT(new NBTTagCompound()); + } + + @Override + public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { + readFromNBT(pkt.getNbtCompound()); + } + + @Override + public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) { + return oldState.getBlock() != newState.getBlock(); + } + +} diff --git a/src/main/java/jackyy/dimensionaledibles/client/TileCustomCakeRenderer.java b/src/main/java/jackyy/dimensionaledibles/client/TileCustomCakeRenderer.java new file mode 100644 index 0000000..1fc060f --- /dev/null +++ b/src/main/java/jackyy/dimensionaledibles/client/TileCustomCakeRenderer.java @@ -0,0 +1,54 @@ +package jackyy.dimensionaledibles.client; + +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.lwjgl.opengl.GL11; + +public class TileCustomCakeRenderer extends TileEntitySpecialRenderer { + + public static final TileCustomCakeRenderer INSTANCE = new TileCustomCakeRenderer(); + + @Override + public void renderTileEntityAt(TileDimensionCake cake, double x, double y, double z, float partialTicks, int destroyStage) { + String dimName = cake.getCakeName(); + float scale = 0.02666667F; + GlStateManager.pushMatrix(); + GlStateManager.translate(x + 0.5, y + 1, z + 0.5F); + GlStateManager.glNormal3f(0.0F, 1.0F, 0.0F); + GlStateManager.scale(-scale, -scale, scale); + GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); + GlStateManager.disableLighting(); + GlStateManager.depthMask(false); + GlStateManager.disableDepth(); + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + Tessellator tessellator = Tessellator.getInstance(); + VertexBuffer vertexbuffer = tessellator.getBuffer(); + GlStateManager.disableTexture2D(); + vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + FontRenderer fontrenderer = Minecraft.getMinecraft().fontRenderer; + int width = fontrenderer.getStringWidth(dimName) / 2; + vertexbuffer.pos(x - width - 1, y - 1, z).color(0F, 0F, 0, 0.25F).endVertex(); + vertexbuffer.pos(x - width - 1, y + 8, z).color(0F, 0F, 0, 0.25F).endVertex(); + vertexbuffer.pos(x + width + 1, y + 8, z).color(0F, 0F, 0, 0.25F).endVertex(); + vertexbuffer.pos(x + width + 1, y - 1, z).color(0F, 0F, 0, 0.25F).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + fontrenderer.drawString(dimName, -fontrenderer.getStringWidth(dimName) / 2, 0, 553648127); + GlStateManager.enableDepth(); + GlStateManager.depthMask(true); + fontrenderer.drawString(dimName, -fontrenderer.getStringWidth(dimName) / 2, 0, -1); + GlStateManager.enableLighting(); + GlStateManager.disableBlend(); + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.popMatrix(); + } + +} diff --git a/src/main/java/jackyy/dimensionaledibles/compat/TOPCompat.java b/src/main/java/jackyy/dimensionaledibles/compat/TOPCompat.java index e02eb72..671396b 100644 --- a/src/main/java/jackyy/dimensionaledibles/compat/TOPCompat.java +++ b/src/main/java/jackyy/dimensionaledibles/compat/TOPCompat.java @@ -24,24 +24,21 @@ public static void register() { public static class GetTheOneProbe implements Function { - public static ITheOneProbe probe; - @Override @Nullable public Void apply(ITheOneProbe theOneProbe) { probe = theOneProbe; probe.registerProvider(new IProbeInfoProvider() { @Override public String getID() { - return DimensionalEdibles.MODID + "cake"; + return DimensionalEdibles.MODID + ":cake"; } @Override public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) { if (blockState.getBlock() instanceof ITOPInfoProvider) { - ITOPInfoProvider provider = (ITOPInfoProvider)blockState.getBlock(); + ITOPInfoProvider provider = (ITOPInfoProvider) blockState.getBlock(); provider.addProbeInfo(mode, probeInfo, player, world, blockState, data); } - } }); return null; diff --git a/src/main/java/jackyy/dimensionaledibles/compat/WailaCompat.java b/src/main/java/jackyy/dimensionaledibles/compat/WailaCompat.java index 19f356d..cbe017e 100644 --- a/src/main/java/jackyy/dimensionaledibles/compat/WailaCompat.java +++ b/src/main/java/jackyy/dimensionaledibles/compat/WailaCompat.java @@ -1,6 +1,7 @@ package jackyy.dimensionaledibles.compat; import jackyy.dimensionaledibles.block.BlockCakeBase; +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; import jackyy.dimensionaledibles.util.IWailaInfoProvider; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -21,9 +22,6 @@ public class WailaCompat implements IWailaDataProvider { public static final WailaCompat INSTANCE = new WailaCompat(); - - private WailaCompat() {} - private static boolean registered; private static boolean loaded; @@ -32,9 +30,11 @@ public static void load(IWailaRegistrar registrar) { throw new RuntimeException("Please register this handler using the provided method."); } if (!loaded) { + registrar.registerStackProvider(INSTANCE, BlockCakeBase.class); registrar.registerHeadProvider(INSTANCE, BlockCakeBase.class); registrar.registerBodyProvider(INSTANCE, BlockCakeBase.class); registrar.registerTailProvider(INSTANCE, BlockCakeBase.class); + registrar.registerNBTProvider(INSTANCE, BlockCakeBase.class); loaded = true; } } @@ -49,7 +49,9 @@ public static void register() { @Nullable @Override public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) { - return null; + ItemStack stack = new ItemStack(accessor.getBlock()); + stack.setTagCompound(accessor.getNBTData()); + return stack; } @Nonnull @@ -62,7 +64,7 @@ public List getWailaHead(ItemStack itemStack, List currenttip, I @Override public List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { if (accessor.getBlock() instanceof IWailaInfoProvider) { - return ((IWailaInfoProvider)accessor.getBlock()).getWailaBody(itemStack, currenttip, accessor, config); + return ((IWailaInfoProvider) accessor.getBlock()).getWailaBody(itemStack, currenttip, accessor, config); } return currenttip; } @@ -76,6 +78,11 @@ public List getWailaTail(ItemStack itemStack, List currenttip, I @Nonnull @Override public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) { + if (te instanceof TileDimensionCake) { + TileDimensionCake cake = (TileDimensionCake) te; + tag.setInteger("dimID", cake.getDimensionID()); + tag.setString("cakeName", cake.getCakeName()); + } return tag; } diff --git a/src/main/java/jackyy/dimensionaledibles/item/ItemBlockCustomCake.java b/src/main/java/jackyy/dimensionaledibles/item/ItemBlockCustomCake.java new file mode 100644 index 0000000..a786f91 --- /dev/null +++ b/src/main/java/jackyy/dimensionaledibles/item/ItemBlockCustomCake.java @@ -0,0 +1,64 @@ +package jackyy.dimensionaledibles.item; + +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; +import jackyy.dimensionaledibles.registry.ModBlocks; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class ItemBlockCustomCake extends ItemBlock { + + public ItemBlockCustomCake() { + super(ModBlocks.customCake); + setRegistryName(ModBlocks.customCake.getRegistryName()); + } + + @Override + public EnumRarity getRarity(ItemStack stack) { + return EnumRarity.EPIC; + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + return getCakeName(stack) + " Cake"; + } + + @Override + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IBlockState blockState) { + boolean placed = super.placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, blockState); + + TileEntity te = world.getTileEntity(pos); + if (te != null) { + if (te instanceof TileDimensionCake) { + ((TileDimensionCake) te).setDimensionID(getDimID(stack)); + ((TileDimensionCake) te).setCakeName(getCakeName(stack)); + } + } + + return placed; + } + + public String getCakeName(ItemStack stack) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null || !nbt.hasKey("cakeName")) { + return "Custom"; + } + return nbt.getString("cakeName"); + } + + public int getDimID(ItemStack stack) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null || !nbt.hasKey("dimID")) { + return 0; + } + return nbt.getInteger("dimID"); + } + +} diff --git a/src/main/java/jackyy/dimensionaledibles/item/ItemCustomApple.java b/src/main/java/jackyy/dimensionaledibles/item/ItemCustomApple.java new file mode 100644 index 0000000..794d1d4 --- /dev/null +++ b/src/main/java/jackyy/dimensionaledibles/item/ItemCustomApple.java @@ -0,0 +1,102 @@ +package jackyy.dimensionaledibles.item; + +import jackyy.dimensionaledibles.DimensionalEdibles; +import jackyy.dimensionaledibles.registry.ModConfig; +import jackyy.dimensionaledibles.util.TeleporterHandler; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.MobEffects; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.NonNullList; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.logging.log4j.Level; + +import javax.annotation.Nonnull; + +public class ItemCustomApple extends ItemFood { + + public ItemCustomApple() { + super(4, 0.3F, false); + setAlwaysEdible(); + setRegistryName(DimensionalEdibles.MODID + ":custom_apple"); + setUnlocalizedName(DimensionalEdibles.MODID + ".custom_apple"); + setCreativeTab(DimensionalEdibles.TAB); + } + + @Override + public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { + int dimension; + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null || !nbt.hasKey("dimID")) { + return; + } + dimension = nbt.getInteger("dimID"); + if (world.provider.getDimension() != dimension) { + if (!world.isRemote) { + EntityPlayerMP playerMP = (EntityPlayerMP) player; + BlockPos coords = TeleporterHandler.getDimPos(playerMP, dimension, player.getPosition()); + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); + TeleporterHandler.teleport(playerMP, dimension, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 200, 200, false, false)); + } + } + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(@Nonnull Item item, CreativeTabs tab, NonNullList list) { + if (ModConfig.general.customApple) { + ItemStack stack; + for (String s : ModConfig.tweaks.customEdible.dimensions) { + try { + String[] parts = s.split(","); + if (parts.length < 2) { + DimensionalEdibles.logger.log(Level.ERROR, s + " is not a valid input line! Format needs to be: , "); + continue; + } + int dimension = Integer.parseInt(parts[0]); + if (DimensionManager.isDimensionRegistered(dimension)) { + stack = new ItemStack(this); + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + nbt = new NBTTagCompound(); + stack.setTagCompound(nbt); + } + nbt.setInteger("dimID", dimension); + nbt.setString("appleName", parts[1].trim()); + list.add(stack); + } else { + DimensionalEdibles.logger.log(Level.ERROR, parts[0] + " is not a valid dimension ID! (Needs to be a number)"); + } + } catch (NumberFormatException e) { + DimensionalEdibles.logger.log(Level.ERROR, s + " is not a valid line input! The dimension ID needs to be a number!"); + } + } + } + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null || !nbt.hasKey("appleName")) { + return "Custom Apple"; + } + return nbt.getString("appleName") + " Apple"; + } + + @Override + public EnumRarity getRarity(ItemStack stack) { + return EnumRarity.EPIC; + } + +} diff --git a/src/main/java/jackyy/dimensionaledibles/item/ItemEnderApple.java b/src/main/java/jackyy/dimensionaledibles/item/ItemEnderApple.java index dc4f487..d782d58 100644 --- a/src/main/java/jackyy/dimensionaledibles/item/ItemEnderApple.java +++ b/src/main/java/jackyy/dimensionaledibles/item/ItemEnderApple.java @@ -33,12 +33,16 @@ public ItemEnderApple() { @Override public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { if (world.provider.getDimension() != 1) { - if (ModConfig.tweaks.enderApple.useCustomCoords) { + if (!world.isRemote) { EntityPlayerMP playerMP = (EntityPlayerMP) player; - BlockPos coords = new BlockPos(ModConfig.tweaks.enderApple.customCoords.x, ModConfig.tweaks.enderApple.customCoords.y, ModConfig.tweaks.enderApple.customCoords.z); + BlockPos coords; + if (ModConfig.tweaks.enderApple.useCustomCoords) { + coords = new BlockPos(ModConfig.tweaks.enderApple.customCoords.x, ModConfig.tweaks.enderApple.customCoords.y, ModConfig.tweaks.enderApple.customCoords.z); + } else { + coords = TeleporterHandler.getDimPos(playerMP, 1, player.getPosition()); + } + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); TeleporterHandler.teleport(playerMP, 1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); - } else { - player.changeDimension(1); player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 200, 200, false, false)); } } @@ -48,7 +52,7 @@ public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { @SideOnly(Side.CLIENT) public void getSubItems(@Nonnull Item item, CreativeTabs tab, NonNullList list) { if (ModConfig.general.enderApple) - list.add(new ItemStack(item)); + list.add(new ItemStack(this)); } @Override diff --git a/src/main/java/jackyy/dimensionaledibles/item/ItemNetherApple.java b/src/main/java/jackyy/dimensionaledibles/item/ItemNetherApple.java index 6c84395..97d5830 100644 --- a/src/main/java/jackyy/dimensionaledibles/item/ItemNetherApple.java +++ b/src/main/java/jackyy/dimensionaledibles/item/ItemNetherApple.java @@ -6,10 +6,12 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.MobEffects; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -37,9 +39,11 @@ public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { if (ModConfig.tweaks.netherApple.useCustomCoords) { coords = new BlockPos(ModConfig.tweaks.netherApple.customCoords.x, ModConfig.tweaks.netherApple.customCoords.y, ModConfig.tweaks.netherApple.customCoords.z); } else { - coords = new BlockPos(0, world.getSeaLevel() + 1, 0); + coords = TeleporterHandler.getDimPos(playerMP, -1, player.getPosition()); } + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); TeleporterHandler.teleport(playerMP, -1, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 200, 200, false, false)); } } } @@ -48,7 +52,7 @@ public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { @SideOnly(Side.CLIENT) public void getSubItems(@Nonnull Item item, CreativeTabs tab, NonNullList list) { if (ModConfig.general.netherApple) - list.add(new ItemStack(item)); + list.add(new ItemStack(this)); } @Override diff --git a/src/main/java/jackyy/dimensionaledibles/item/ItemOverworldApple.java b/src/main/java/jackyy/dimensionaledibles/item/ItemOverworldApple.java index 924fe18..106adb5 100644 --- a/src/main/java/jackyy/dimensionaledibles/item/ItemOverworldApple.java +++ b/src/main/java/jackyy/dimensionaledibles/item/ItemOverworldApple.java @@ -6,10 +6,12 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.MobEffects; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -37,12 +39,11 @@ public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { if (ModConfig.tweaks.overworldApple.useCustomCoords) { coords = new BlockPos(ModConfig.tweaks.overworldApple.customCoords.x, ModConfig.tweaks.overworldApple.customCoords.y, ModConfig.tweaks.overworldApple.customCoords.z); } else { - coords = world.getSpawnPoint(); - while (world.getBlockState(world.getSpawnPoint()).isFullCube()) { - coords = coords.up(2); - } + coords = TeleporterHandler.getDimPos(playerMP, 0, player.getPosition()); } + TeleporterHandler.updateDimPos(playerMP, world.provider.getDimension(), player.getPosition()); TeleporterHandler.teleport(playerMP, 0, coords.getX(), coords.getY(), coords.getZ(), playerMP.mcServer.getPlayerList()); + player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 200, 200, false, false)); } } } @@ -51,7 +52,7 @@ public void onFoodEaten(ItemStack stack, World world, EntityPlayer player) { @SideOnly(Side.CLIENT) public void getSubItems(@Nonnull Item item, CreativeTabs tab, NonNullList list) { if (ModConfig.general.overworldApple) - list.add(new ItemStack(item)); + list.add(new ItemStack(this)); } @Override diff --git a/src/main/java/jackyy/dimensionaledibles/proxy/ClientProxy.java b/src/main/java/jackyy/dimensionaledibles/proxy/ClientProxy.java index 9b20518..1636d12 100644 --- a/src/main/java/jackyy/dimensionaledibles/proxy/ClientProxy.java +++ b/src/main/java/jackyy/dimensionaledibles/proxy/ClientProxy.java @@ -1,7 +1,10 @@ package jackyy.dimensionaledibles.proxy; +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; +import jackyy.dimensionaledibles.client.TileCustomCakeRenderer; import jackyy.dimensionaledibles.registry.ModBlocks; import jackyy.dimensionaledibles.registry.ModItems; +import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -16,6 +19,7 @@ public void preInit(FMLPreInitializationEvent event) { public void init(FMLInitializationEvent event) { super.init(event); + ClientRegistry.bindTileEntitySpecialRenderer(TileDimensionCake.class, TileCustomCakeRenderer.INSTANCE); } public void postInit(FMLPostInitializationEvent event) { diff --git a/src/main/java/jackyy/dimensionaledibles/proxy/CommonProxy.java b/src/main/java/jackyy/dimensionaledibles/proxy/CommonProxy.java index 146fcbe..1452153 100644 --- a/src/main/java/jackyy/dimensionaledibles/proxy/CommonProxy.java +++ b/src/main/java/jackyy/dimensionaledibles/proxy/CommonProxy.java @@ -3,8 +3,10 @@ import jackyy.dimensionaledibles.compat.TOPCompat; import jackyy.dimensionaledibles.compat.WailaCompat; import jackyy.dimensionaledibles.registry.ModBlocks; +import jackyy.dimensionaledibles.registry.ModEvents; import jackyy.dimensionaledibles.registry.ModItems; import jackyy.dimensionaledibles.registry.ModRecipes; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; @@ -21,6 +23,7 @@ public void preInit(FMLPreInitializationEvent event) { if (Loader.isModLoaded("waila")) { WailaCompat.register(); } + MinecraftForge.EVENT_BUS.register(new ModEvents()); } public void init(FMLInitializationEvent event) { diff --git a/src/main/java/jackyy/dimensionaledibles/registry/ModBlocks.java b/src/main/java/jackyy/dimensionaledibles/registry/ModBlocks.java index 1e71d21..6b0cca6 100644 --- a/src/main/java/jackyy/dimensionaledibles/registry/ModBlocks.java +++ b/src/main/java/jackyy/dimensionaledibles/registry/ModBlocks.java @@ -1,8 +1,11 @@ package jackyy.dimensionaledibles.registry; +import jackyy.dimensionaledibles.block.BlockCustomCake; import jackyy.dimensionaledibles.block.BlockEndCake; import jackyy.dimensionaledibles.block.BlockNetherCake; import jackyy.dimensionaledibles.block.BlockOverworldCake; +import jackyy.dimensionaledibles.block.tile.TileDimensionCake; +import jackyy.dimensionaledibles.item.ItemBlockCustomCake; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; @@ -18,6 +21,8 @@ public class ModBlocks { public static BlockEndCake endCake; public static BlockNetherCake netherCake; public static BlockOverworldCake overworldCake; + public static BlockCustomCake customCake; + public static ItemBlockCustomCake customCakeItem; public static void init() { endCake = GameRegistry.register(new BlockEndCake()); @@ -41,17 +46,18 @@ public EnumRarity getRarity(ItemStack stack) { return EnumRarity.EPIC; } }, overworldCake.getRegistryName()); + customCake = GameRegistry.register(new BlockCustomCake()); + customCakeItem = GameRegistry.register(new ItemBlockCustomCake()); + GameRegistry.registerTileEntity(TileDimensionCake.class, "tile_dimension_cake"); } @SideOnly(Side.CLIENT) public static void initModels() { for (int i = 0; i <= 6; i++) { - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(endCake), i, - new ModelResourceLocation(endCake.getRegistryName(), "inventory")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(netherCake), i, - new ModelResourceLocation(netherCake.getRegistryName(), "inventory")); - ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(overworldCake), i, - new ModelResourceLocation(overworldCake.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(endCake), i, new ModelResourceLocation(endCake.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(netherCake), i, new ModelResourceLocation(netherCake.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(overworldCake), i, new ModelResourceLocation(overworldCake.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(customCake), i, new ModelResourceLocation(customCake.getRegistryName(), "inventory")); } } diff --git a/src/main/java/jackyy/dimensionaledibles/registry/ModConfig.java b/src/main/java/jackyy/dimensionaledibles/registry/ModConfig.java index 9f8434b..4cbb0a7 100644 --- a/src/main/java/jackyy/dimensionaledibles/registry/ModConfig.java +++ b/src/main/java/jackyy/dimensionaledibles/registry/ModConfig.java @@ -20,25 +20,27 @@ public static class General { public boolean netherCake = true; @Config.Comment("Set to true to enable Overworld Cake.") public boolean overworldCake = true; + @Config.Comment("Set to true to enable custom Cakes.") + public boolean customCake = true; @Config.Comment("Set to true to enable Ender Cake.") public boolean enderApple = true; @Config.Comment("Set to true to enable Nether Cake.") public boolean netherApple = true; @Config.Comment("Set to true to enable Overworld Cake.") public boolean overworldApple = true; + @Config.Comment("Set to true to enable Custom Cake.") + public boolean customApple = true; } public static class Tweaks { + public EndCake endCake = new EndCake(); public static class EndCake { @Config.Comment("Set the fuel used by End Cake (Don't change this unless you know what you're doing).") public String fuel = "minecraft:ender_eye"; @Config.Comment("Set to true to make the End Cake pre-fueled upon placed.") public boolean preFueled = false; - @Config.Comment({ - "Set to true to use custom coordinates for the teleportation.", - "Otherwise, spawn platform will be used by default." - }) + @Config.Comment("Set to true to use custom coordinates for the teleportation.") public boolean useCustomCoords = false; public CustomCoords customCoords = new CustomCoords(); public static class CustomCoords { @@ -47,12 +49,10 @@ public static class CustomCoords { public double z = 0.0D; } } + public EnderApple enderApple = new EnderApple(); public static class EnderApple { - @Config.Comment({ - "Set to true to use custom coordinates for the teleportation.", - "Otherwise, spawn platform will be used by default." - }) + @Config.Comment("Set to true to use custom coordinates for the teleportation.") public boolean useCustomCoords = false; public CustomCoords customCoords = new CustomCoords(); public static class CustomCoords { @@ -61,16 +61,14 @@ public static class CustomCoords { public double z = 0.0D; } } + public NetherCake netherCake = new NetherCake(); public static class NetherCake { @Config.Comment("Set the fuel used by Nether Cake (Don't change this unless you know what you're doing).") public String fuel = "minecraft:obsidian"; @Config.Comment("Set to true to make the Nether Cake pre-fueled upon placed.") public boolean preFueled = false; - @Config.Comment({ - "Set to true to use custom coordinates for the teleportation.", - "Otherwise, x0 z0 will be used by default." - }) + @Config.Comment("Set to true to use custom coordinates for the teleportation.") public boolean useCustomCoords = false; public CustomCoords customCoords = new CustomCoords(); public static class CustomCoords { @@ -79,12 +77,10 @@ public static class CustomCoords { public double z = 0.0D; } } + public NetherApple netherApple = new NetherApple(); public static class NetherApple { - @Config.Comment({ - "Set to true to use custom coordinates for the teleportation.", - "Otherwise, x0 z0 will be used by default." - }) + @Config.Comment("Set to true to use custom coordinates for the teleportation.") public boolean useCustomCoords = false; public CustomCoords customCoords = new CustomCoords(); public static class CustomCoords { @@ -93,16 +89,14 @@ public static class CustomCoords { public double z = 0.0D; } } + public OverworldCake overworldCake = new OverworldCake(); public static class OverworldCake { @Config.Comment("Set the fuel used by Overworld Cake (Don't change this unless you know what you're doing).") public String fuel = "minecraft:sapling"; @Config.Comment("Set to true to make the Overworld Cake pre-fueled upon placed.") public boolean preFueled = false; - @Config.Comment({ - "Set to true to use custom coordinates for the teleportation.", - "Otherwise, world spawn point will be used by default." - }) + @Config.Comment("Set to true to use custom coordinates for the teleportation.") public boolean useCustomCoords = false; public CustomCoords customCoords = new CustomCoords(); public static class CustomCoords { @@ -111,12 +105,10 @@ public static class CustomCoords { public double z = 0.0D; } } + public OverworldApple overworldApple = new OverworldApple(); public static class OverworldApple { - @Config.Comment({ - "Set to true to use custom coordinates for the teleportation.", - "Otherwise, world spawn point will be used by default." - }) + @Config.Comment("Set to true to use custom coordinates for the teleportation.") public boolean useCustomCoords = false; public CustomCoords customCoords = new CustomCoords(); public static class CustomCoords { @@ -125,6 +117,32 @@ public static class CustomCoords { public double z = 0.0D; } } + + public CustomEdible customEdible = new CustomEdible(); + public static class CustomEdible { + @Config.Comment({ + "Set a list of dimensions to add cakes / apples for.", + "Format: , ", + "Example: 0, Overworld", + "Note: \"Cake\" is automatically appended onto the end of the name for cakes." + }) + public String[] dimensions = new String[0]; + public CustomCake customCake = new CustomCake(); + public static class CustomCake { + @Config.Comment("Set to true to make all Custom Cakes pre-fueled upon placed.") + public boolean preFueled = false; + @Config.Comment({ + "Set the fuel used by Custom Cakes.", + "Format: , ", + "Example: 0, minecraft:apple" + }) + public String[] fuel = new String[0]; + } + } + + @Config.Comment("Set to true to disable the activation of vanilla End Portal.") + public boolean disableVanillaEndPortal = false; + } @Mod.EventBusSubscriber diff --git a/src/main/java/jackyy/dimensionaledibles/registry/ModEvents.java b/src/main/java/jackyy/dimensionaledibles/registry/ModEvents.java new file mode 100644 index 0000000..2b6f33d --- /dev/null +++ b/src/main/java/jackyy/dimensionaledibles/registry/ModEvents.java @@ -0,0 +1,26 @@ +package jackyy.dimensionaledibles.registry; + +import jackyy.dimensionaledibles.DimensionalEdibles; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class ModEvents { + + @SubscribeEvent + public void onEnderEyeUse(PlayerInteractEvent.RightClickBlock event) { + if (ModConfig.tweaks.disableVanillaEndPortal) { + ItemStack stack = event.getItemStack(); + EntityPlayer player = event.getEntityPlayer(); + if (!stack.isEmpty() && stack.getItem() == Items.ENDER_EYE && event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.END_PORTAL_FRAME) { + event.setCanceled(true); + player.sendStatusMessage(new TextComponentTranslation(DimensionalEdibles.MODID + ".error.end_portal_disabled"), true); + } + } + } + +} diff --git a/src/main/java/jackyy/dimensionaledibles/registry/ModItems.java b/src/main/java/jackyy/dimensionaledibles/registry/ModItems.java index 973b147..837e843 100644 --- a/src/main/java/jackyy/dimensionaledibles/registry/ModItems.java +++ b/src/main/java/jackyy/dimensionaledibles/registry/ModItems.java @@ -1,5 +1,6 @@ package jackyy.dimensionaledibles.registry; +import jackyy.dimensionaledibles.item.ItemCustomApple; import jackyy.dimensionaledibles.item.ItemEnderApple; import jackyy.dimensionaledibles.item.ItemNetherApple; import jackyy.dimensionaledibles.item.ItemOverworldApple; @@ -14,21 +15,21 @@ public class ModItems { public static ItemEnderApple enderApple; public static ItemNetherApple netherApple; public static ItemOverworldApple overworldApple; + public static ItemCustomApple customApple; public static void init() { enderApple = GameRegistry.register(new ItemEnderApple()); netherApple = GameRegistry.register(new ItemNetherApple()); overworldApple = GameRegistry.register(new ItemOverworldApple()); + customApple = GameRegistry.register(new ItemCustomApple()); } @SideOnly(Side.CLIENT) public static void initModels() { - ModelLoader.setCustomModelResourceLocation(enderApple, 0, - new ModelResourceLocation(enderApple.getRegistryName(), "inventory")); - ModelLoader.setCustomModelResourceLocation(netherApple, 0, - new ModelResourceLocation(netherApple.getRegistryName(), "inventory")); - ModelLoader.setCustomModelResourceLocation(overworldApple, 0, - new ModelResourceLocation(overworldApple.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(enderApple, 0, new ModelResourceLocation(enderApple.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(netherApple, 0, new ModelResourceLocation(netherApple.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(overworldApple, 0, new ModelResourceLocation(overworldApple.getRegistryName(), "inventory")); + ModelLoader.setCustomModelResourceLocation(customApple, 0, new ModelResourceLocation(customApple.getRegistryName(), "inventory")); } } diff --git a/src/main/java/jackyy/dimensionaledibles/util/TeleporterHandler.java b/src/main/java/jackyy/dimensionaledibles/util/TeleporterHandler.java index 1061ad6..71af311 100644 --- a/src/main/java/jackyy/dimensionaledibles/util/TeleporterHandler.java +++ b/src/main/java/jackyy/dimensionaledibles/util/TeleporterHandler.java @@ -1,19 +1,26 @@ package jackyy.dimensionaledibles.util; +import jackyy.dimensionaledibles.DimensionalEdibles; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.MobEffects; import net.minecraft.init.SoundEvents; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.play.server.SPacketEntityEffect; import net.minecraft.network.play.server.SPacketRespawn; import net.minecraft.potion.PotionEffect; import net.minecraft.server.management.PlayerList; +import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; import net.minecraft.world.WorldProvider; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.fml.common.FMLCommonHandler; import java.util.Random; @@ -21,21 +28,20 @@ public class TeleporterHandler { public static void teleport(EntityPlayerMP player, int dim, double x, double y, double z, PlayerList playerList) { + if (!ForgeHooks.onTravelToDimension(player, dim)) + return; int oldDim = player.dimension; WorldServer worldServer = playerList.getServerInstance().getWorld(player.dimension); player.dimension = dim; WorldServer worldServer1 = playerList.getServerInstance().getWorld(player.dimension); player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType())); worldServer.removeEntityDangerously(player); - if (player.isBeingRidden()) { player.removePassengers(); } - if (player.isRiding()) { player.dismountRidingEntity(); } - player.isDead = false; teleportEntity(player, worldServer, worldServer1); playerList.preparePlayer(player, worldServer); @@ -43,19 +49,15 @@ public static void teleport(EntityPlayerMP player, int dim, double x, double y, player.interactionManager.setWorld(worldServer1); playerList.updateTimeAndWeatherForPlayer(player, worldServer1); playerList.syncPlayerInventory(player); - for (PotionEffect potioneffect : player.getActivePotionEffects()) { player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect)); } - FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldDim, dim); worldServer1.playSound(null, x + 0.5D, y + 0.5D, z + 0.5D, SoundEvents.BLOCK_PORTAL_TRAVEL, SoundCategory.MASTER, 0.25F, new Random().nextFloat() * 0.4F + 0.8F); BlockPos pos = new BlockPos(x, y - 1, z); - if (!player.capabilities.isCreativeMode) { player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 200, 200, false, false)); } - if (worldServer1.provider.getDimension() == -1) { for (int xx = -1; xx <= 1; xx++) { for (int zz = -1; zz <= 1; zz++) { @@ -65,7 +67,6 @@ public static void teleport(EntityPlayerMP player, int dim, double x, double y, } } } - for (int yy = 1; yy <= 3; yy++) { if (worldServer1.getBlockState(pos.add(0, yy, 0)).isFullBlock()) { worldServer1.setBlockToAir(pos.add(0, yy, 0)); @@ -91,4 +92,80 @@ public static void teleportEntity(Entity entity, WorldServer oldWorld, WorldServ entity.setWorld(newWorld); } + public static NBTTagCompound getModNBTData(EntityPlayer player) { + NBTTagCompound dimensionCache = (NBTTagCompound) player.getEntityData().getTag(DimensionalEdibles.MODID); + if (dimensionCache == null) { + dimensionCache = new NBTTagCompound(); + player.getEntityData().setTag(DimensionalEdibles.MODID, dimensionCache); + } + return dimensionCache; + } + + public static void updateDimPos(EntityPlayer player, int dimension, BlockPos pos) { + NBTTagCompound dimensionCache = getModNBTData(player); + NBTTagCompound dimPos = (NBTTagCompound) dimensionCache.getTag("" + dimension); + if (dimPos == null) { + dimPos = new NBTTagCompound(); + dimensionCache.setTag("" + dimension, dimPos); + } + dimPos.setInteger("x", pos.getX()); + dimPos.setInteger("y", pos.getY()); + dimPos.setInteger("z", pos.getZ()); + } + + public static BlockPos getDimPos(EntityPlayerMP player, int dimension, BlockPos currentPos) { + NBTTagCompound dimensionCache = getModNBTData(player); + NBTTagCompound dimPos = (NBTTagCompound) dimensionCache.getTag("" + dimension); + BlockPos position; + if (dimPos == null) { + dimPos = new NBTTagCompound(); + dimensionCache.setTag("" + dimension, dimPos); + + WorldServer newDimworld = player.mcServer.getPlayerList().getServerInstance().getWorld(dimension); + + if (dimension == 1) { + position = newDimworld.getSpawnCoordinate(); + } else { + position = getValidYSpawnPos(newDimworld, currentPos); + } + } else { + position = new BlockPos(dimPos.getInteger("x"), dimPos.getInteger("y"), dimPos.getInteger("z")); + } + return position; + } + + public static BlockPos getValidYSpawnPos(World world, BlockPos basePos) { + MutableBlockPos pos = new MutableBlockPos(basePos.getX() / 8, basePos.getY(), basePos.getZ() / 8); + boolean foundSpawnPos = false; + while (!foundSpawnPos && pos.getY() < world.getActualHeight()) { + if (world.getBlockState(pos.add(0, -1, 0)).isSideSolid(world, pos.add(0, -1, 0), EnumFacing.UP) && !world.getBlockState(pos).isNormalCube() && !world.getBlockState(pos.add(0, 1, 0)).isNormalCube()) { + foundSpawnPos = true; + } + if (!foundSpawnPos) { + pos.move(EnumFacing.UP); + } + } + while (!foundSpawnPos && pos.getY() > 0) { + if (pos.getY() < world.getActualHeight()) { + if (world.getBlockState(pos.add(0, -1, 0)).isSideSolid(world, pos.add(0, -1, 0), EnumFacing.UP) && !world.getBlockState(pos).isNormalCube() && !world.getBlockState(pos.add(0, 1, 0)).isNormalCube()) { + foundSpawnPos = true; + } + } + if (!foundSpawnPos) { + pos.move(EnumFacing.DOWN); + } + } + if (!foundSpawnPos) { + pos.setPos(basePos); + for (int x = -1; x < 2; x++) { + for (int z = -1; z < 2; z++) { + world.setBlockState(pos.add(x, -1, z), Blocks.OBSIDIAN.getDefaultState()); + world.setBlockToAir(pos.add(x, 0, z)); + world.setBlockToAir(pos.add(x, 1, z)); + } + } + } + return pos; + } + } diff --git a/src/main/resources/assets/dimensionaledibles/blockstates/custom_cake.json b/src/main/resources/assets/dimensionaledibles/blockstates/custom_cake.json new file mode 100644 index 0000000..3a61181 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/blockstates/custom_cake.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "dimensionaledibles:custom_cake/custom_cake_full" + }, + "variants": { + "bites": { + 0: { "model": "dimensionaledibles:custom_cake/custom_cake_full" }, + 1: { "model": "dimensionaledibles:custom_cake/custom_cake_slice1" }, + 2: { "model": "dimensionaledibles:custom_cake/custom_cake_slice2" }, + 3: { "model": "dimensionaledibles:custom_cake/custom_cake_slice3" }, + 4: { "model": "dimensionaledibles:custom_cake/custom_cake_slice4" }, + 5: { "model": "dimensionaledibles:custom_cake/custom_cake_slice5" }, + 6: { "model": "dimensionaledibles:custom_cake/custom_cake_slice6" } + }, + "inventory": { + "model": "dimensionaledibles:custom_cake" + } + } +} diff --git a/src/main/resources/assets/dimensionaledibles/lang/en_US.lang b/src/main/resources/assets/dimensionaledibles/lang/en_US.lang index bea30e9..8ab3d33 100644 --- a/src/main/resources/assets/dimensionaledibles/lang/en_US.lang +++ b/src/main/resources/assets/dimensionaledibles/lang/en_US.lang @@ -5,11 +5,13 @@ itemGroup.dimensionaledibles=Dimensional Edibles item.dimensionaledibles.ender_apple.name=Ender Apple item.dimensionaledibles.nether_apple.name=Nether Apple item.dimensionaledibles.overworld_apple.name=Overworld Apple +item.dimensionaledibles.custom_apple.name=Custom Apple #Blocks tile.dimensionaledibles.end_cake.name=End Cake tile.dimensionaledibles.nether_cake.name=Nether Cake tile.dimensionaledibles.overworld_cake.name=Overworld Cake +tile.dimensionaledibles.custom_cake.name=Custom Cake #JEI Compat dimensionaledibles.end_cake.jeidesc=Place the cake down and fill it with %d, then right click on the cake and you'll be teleported to The End. The cake has infinite uses as long as it is fueled. @@ -18,3 +20,6 @@ dimensionaledibles.overworld_cake.jeidesc=Place the cake down and fill it with % dimensionaledibles.ender_apple.jeidesc=Eat the apple and you'll be teleported to The End. Single-use only. dimensionaledibles.nether_apple.jeidesc=Eat the apple and you'll be teleported to the Nether. Single-use only. dimensionaledibles.overworld_apple.jeidesc=Eat the apple and you'll be teleported to the Overworld. Single-use only. + +#Error Messages +dimensionaledibles.error.end_portal_disabled=§cActivation of the End Portal has been disabled! Please use the End Cake instead! diff --git a/src/main/resources/assets/dimensionaledibles/lang/nl_NL.lang b/src/main/resources/assets/dimensionaledibles/lang/nl_NL.lang new file mode 100644 index 0000000..4918cf3 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/lang/nl_NL.lang @@ -0,0 +1,22 @@ +#Creative Tab +itemGroup.dimensionaledibles=Dimensional Edibles + +#Items +item.dimensionaledibles.ender_apple.name=Ender Appel +item.dimensionaledibles.nether_apple.name=Nether Appel +item.dimensionaledibles.overworld_apple.name=Overworld Appel +item.dimensionaledibles.custom_apple.name=Custom Appel + +#Blocks +tile.dimensionaledibles.end_cake.name=Ender Cake +tile.dimensionaledibles.nether_cake.name=Nether Cake +tile.dimensionaledibles.overworld_cake.name=Overworld Cake +tile.dimensionaledibles.custom_cake.name=Custom Cake + +#JEI Compat +dimensionaledibles.end_cake.jeidesc=Plaats de cake en vul hem met %d, klik met de rechtermuisknop op de cake en je wordt geteleporteerd naar de Ender. De cake heeft oneindig veel toepassingen zolang deze maar is gevuld. +dimensionaledibles.nether_cake.jeidesc=Plaats de cake naar beneden en vul deze met %d, klik met de rechtermuisknop op de cake en je wordt geteleporteerd naar de Nether. De cake heeft oneindig veel toepassingen zolang deze maar is gevuld. +dimensionaledibles.overworld_cake.jeidesc=Plaats de cake en vul deze met %d, klik met de rechtermuisknop op de taart en je wordt geteleporteerd naar de Overworld. De cake heeft oneindig veel toepassingen zolang deze maar is gevuld. +dimensionaledibles.ender_apple.jeidesc=Eet de appel en je wordt geteleporteerd naar de Ender. Eenmalig gebruik. +dimensionaledibles.nether_apple.jeidesc=Eet de appel en je wordt geteleporteerd naar de Nether. Eenmalig gebruik. +dimensionaledibles.overworld_apple.jeidesc=Eet de appel en je wordt geteleporteerd naar de Overworld. Eenmalig gebruik. diff --git a/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_full.json b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_full.json new file mode 100644 index 0000000..e0ee4a9 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_full.json @@ -0,0 +1,9 @@ +{ + "parent": "block/cake_uneaten", + "textures": { + "particle": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "bottom": "dimensionaledibles:blocks/custom_cake/custom_cake_0", + "top": "dimensionaledibles:blocks/custom_cake/custom_cake_1", + "side": "dimensionaledibles:blocks/custom_cake/custom_cake_2" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice1.json b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice1.json new file mode 100644 index 0000000..d8a880b --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice1.json @@ -0,0 +1,10 @@ +{ + "parent": "block/cake_slice1", + "textures": { + "particle": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "bottom": "dimensionaledibles:blocks/custom_cake/custom_cake_0", + "top": "dimensionaledibles:blocks/custom_cake/custom_cake_1", + "side": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "inside": "dimensionaledibles:blocks/custom_cake/custom_cake_3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice2.json b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice2.json new file mode 100644 index 0000000..b1a5124 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice2.json @@ -0,0 +1,10 @@ +{ + "parent": "block/cake_slice2", + "textures": { + "particle": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "bottom": "dimensionaledibles:blocks/custom_cake/custom_cake_0", + "top": "dimensionaledibles:blocks/custom_cake/custom_cake_1", + "side": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "inside": "dimensionaledibles:blocks/custom_cake/custom_cake_3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice3.json b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice3.json new file mode 100644 index 0000000..87f472c --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice3.json @@ -0,0 +1,10 @@ +{ + "parent": "block/cake_slice3", + "textures": { + "particle": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "bottom": "dimensionaledibles:blocks/custom_cake/custom_cake_0", + "top": "dimensionaledibles:blocks/custom_cake/custom_cake_1", + "side": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "inside": "dimensionaledibles:blocks/custom_cake/custom_cake_3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice4.json b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice4.json new file mode 100644 index 0000000..9cc8110 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice4.json @@ -0,0 +1,10 @@ +{ + "parent": "block/cake_slice4", + "textures": { + "particle": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "bottom": "dimensionaledibles:blocks/custom_cake/custom_cake_0", + "top": "dimensionaledibles:blocks/custom_cake/custom_cake_1", + "side": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "inside": "dimensionaledibles:blocks/custom_cake/custom_cake_3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice5.json b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice5.json new file mode 100644 index 0000000..4fca79a --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice5.json @@ -0,0 +1,10 @@ +{ + "parent": "block/cake_slice5", + "textures": { + "particle": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "bottom": "dimensionaledibles:blocks/custom_cake/custom_cake_0", + "top": "dimensionaledibles:blocks/custom_cake/custom_cake_1", + "side": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "inside": "dimensionaledibles:blocks/custom_cake/custom_cake_3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice6.json b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice6.json new file mode 100644 index 0000000..380bff3 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/block/custom_cake/custom_cake_slice6.json @@ -0,0 +1,10 @@ +{ + "parent": "block/cake_slice6", + "textures": { + "particle": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "bottom": "dimensionaledibles:blocks/custom_cake/custom_cake_0", + "top": "dimensionaledibles:blocks/custom_cake/custom_cake_1", + "side": "dimensionaledibles:blocks/custom_cake/custom_cake_2", + "inside": "dimensionaledibles:blocks/custom_cake/custom_cake_3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/dimensionaledibles/models/item/custom_apple.json b/src/main/resources/assets/dimensionaledibles/models/item/custom_apple.json new file mode 100644 index 0000000..191a9d0 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/item/custom_apple.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "dimensionaledibles:items/custom_apple" + } +} diff --git a/src/main/resources/assets/dimensionaledibles/models/item/custom_cake.json b/src/main/resources/assets/dimensionaledibles/models/item/custom_cake.json new file mode 100644 index 0000000..1eb3927 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/models/item/custom_cake.json @@ -0,0 +1,25 @@ +{ + "parent": "dimensionaledibles:block/custom_cake/custom_cake_full", + "display": { + "ground": { + "rotation": [ 0, 0, 0 ], + "translation": [ 0, 3, 0 ], + "scale": [ 0.25, 0.25, 0.25 ] + }, + "thirdperson_righthand": { + "rotation": [ 75, 315, 0 ], + "translation": [ 0, 3, 1 ], + "scale": [ 0.55, 0.55, 0.55 ] + }, + "firstperson_righthand": { + "rotation": [ 0, 315, 0 ], + "translation": [ 1.13, 3.2, 1.13 ], + "scale": [ 0.68, 0.68, 0.68 ] + }, + "gui": { + "rotation": [ 30, 45, 0 ], + "translation": [ 0, 2, 0 ], + "scale": [ 0.75, 0.75, 0.75 ] + } + } +} diff --git a/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_0.png b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_0.png new file mode 100644 index 0000000..e689830 Binary files /dev/null and b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_0.png differ diff --git a/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_1.png b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_1.png new file mode 100644 index 0000000..0b90779 Binary files /dev/null and b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_1.png differ diff --git a/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_2.png b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_2.png new file mode 100644 index 0000000..f847668 Binary files /dev/null and b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_2.png differ diff --git a/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_3.png b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_3.png new file mode 100644 index 0000000..b6e03af Binary files /dev/null and b/src/main/resources/assets/dimensionaledibles/textures/blocks/custom_cake/custom_cake_3.png differ diff --git a/src/main/resources/assets/dimensionaledibles/textures/items/custom_apple.png b/src/main/resources/assets/dimensionaledibles/textures/items/custom_apple.png new file mode 100644 index 0000000..06e3753 Binary files /dev/null and b/src/main/resources/assets/dimensionaledibles/textures/items/custom_apple.png differ diff --git a/src/main/resources/assets/dimensionaledibles/textures/items/custom_apple.png.mcmeta b/src/main/resources/assets/dimensionaledibles/textures/items/custom_apple.png.mcmeta new file mode 100644 index 0000000..8e55e43 --- /dev/null +++ b/src/main/resources/assets/dimensionaledibles/textures/items/custom_apple.png.mcmeta @@ -0,0 +1,5 @@ +{ + "animation": { + "frametime": 3 + } +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 69f140f..3e38088 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -3,11 +3,11 @@ "modid": "dimensionaledibles", "name": "Dimensional Edibles", "description": "Travel through dimensions with food!", - "version": "1.2", + "version": "1.3", "mcversion": "1.11.2", "url": "https://github.com/JackyyTV/DimensionalEdibles", "updateUrl": "", - "authorList": ["Jackyy"], + "authorList": ["Jackyy", "Turkey2349"], "credits": "", "logoFile": "assets/dimensionaledibles/logo.png", "screenshots": [],