Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
1.3 Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyyTV committed Jan 15, 2019
1 parent 4a17bde commit f41b93b
Show file tree
Hide file tree
Showing 42 changed files with 939 additions and 231 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
29 changes: 13 additions & 16 deletions src/main/java/jackyy/dimensionaledibles/block/BlockCakeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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);
}
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down
146 changes: 146 additions & 0 deletions src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java
Original file line number Diff line number Diff line change
@@ -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: <dimID>, <cakeFuel>");
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<ItemStack> 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: <dimID>, <cakeName>");
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();
}

}
Loading

0 comments on commit f41b93b

Please sign in to comment.