Skip to content

Commit

Permalink
Lots of apoc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamioflan committed Mar 1, 2018
1 parent c349199 commit 4969858
Show file tree
Hide file tree
Showing 22 changed files with 159 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
Expand All @@ -39,6 +40,7 @@
import com.flansmod.apocalypse.client.model.RenderTeleporter;
import com.flansmod.apocalypse.common.CommonProxyApocalypse;
import com.flansmod.apocalypse.common.FlansModApocalypse;
import com.flansmod.apocalypse.common.blocks.BlockSulphuricAcid;
import com.flansmod.apocalypse.common.blocks.TileEntityPowerCube;
import com.flansmod.apocalypse.common.entity.EntityAIMecha;
import com.flansmod.apocalypse.common.entity.EntityFakePlayer;
Expand Down Expand Up @@ -68,6 +70,10 @@ public class ClientProxyApocalypse extends CommonProxyApocalypse
public void preInit(FMLPreInitializationEvent event)
{
super.preInit(event);

MinecraftForge.EVENT_BUS.register(this);

((BlockSulphuricAcid)FlansModApocalypse.blockSulphuricAcid).registerRenderer();
}

public void init(FMLInitializationEvent event)
Expand Down Expand Up @@ -99,8 +105,9 @@ public static void updateApocalypseCountdownTimer(int i)
}

@SubscribeEvent
public static void registerModels(ModelRegistryEvent event)
public void registerModels(ModelRegistryEvent event)
{
/*
Item item = Item.getItemFromBlock(FlansModApocalypse.blockSulphuricAcid);
ModelBakery.registerItemVariants(item);
final ModelResourceLocation modelResourceLocation = new ModelResourceLocation(FLUID_MODEL_PATH, FlansModApocalypse.sulphuricAcid.getName());
Expand All @@ -119,6 +126,10 @@ protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return modelResourceLocation;
}
});
*/

ModelLoader.setCustomModelResourceLocation(FlansModApocalypse.itemBlockLabStone, 0, new ModelResourceLocation("flansmodapocalypse:itemblocklabstone", "inventory"));
ModelLoader.registerItemVariants(FlansModApocalypse.itemBlockLabStone, new ResourceLocation[] { new ResourceLocation("flansmodapocalypse:itemblocklabstone")});
}

/** Tick hook for client logic */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ public void registerEntities(RegistryEvent.Register<EntityEntry> event)
event.getRegistry().register(new EntityEntry(EntityAIMecha.class, "AIMecha").setRegistryName("AIMecha"));
event.getRegistry().register(new EntityEntry(EntityFakePlayer.class, "FakePlayer").setRegistryName("FakePlayer"));
event.getRegistry().register(new EntityEntry(EntityNukeDrop.class, "NukeDrop").setRegistryName("NukeDrop"));
event.getRegistry().register(new EntityEntry(EntityFlyByPlane.class, "FlyByPlane").setRegistryName("FlyByPlane"));

//EntityRegistry.registerModEntity(new ResourceLocation("flansmodapocalypse:Survivor"), EntitySurvivor.class, "Survivor", 89, FlansModApocalypse.INSTANCE, 100, 20, true, 0, 0);
//EntityRegistry.registerModEntity(new ResourceLocation("flansmodapocalypse:Survivor"), EntitySurvivor.class, "Survivor", 112, FlansModApocalypse.INSTANCE, 100, 20, true, 0, 0);
EntityRegistry.registerModEntity(new ResourceLocation("flansmodapocalypse:Teleporter"), EntityTeleporter.class, "Teleporter", 113, FlansModApocalypse.INSTANCE, 100, 20, true);
EntityRegistry.registerModEntity(new ResourceLocation("flansmodapocalypse:AIMecha"), EntityAIMecha.class, "AIMecha", 114, FlansModApocalypse.INSTANCE, 250, 20, false);
EntityRegistry.registerModEntity(new ResourceLocation("flansmodapocalypse:FakePlayer"), EntityFakePlayer.class, "FakePlayer", 115, FlansModApocalypse.INSTANCE, 250, 20, false);
EntityRegistry.registerModEntity(new ResourceLocation("flansmodapocalypse:NukeDrop"), EntityNukeDrop.class, "NukeDrop", 116, FlansModApocalypse.INSTANCE, 250, 20, false);
EntityRegistry.registerModEntity(new ResourceLocation("flansmodapocalypse:FlyByPlane"), EntityFlyByPlane.class, "FlyByPlane", 117, FlansModApocalypse.INSTANCE, 250, 20, false);
}

/** Tick hook for server */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
Expand Down Expand Up @@ -93,15 +94,25 @@ public class FlansModApocalypse
public static Block blockLabStone;
public static Block blockPowerCube;

public static Item itemBlockPowerCube, itemBlockLabStone, itemBlockSulphur;

public static CreativeTabFlan tabApocalypse = new CreativeTabFlan(5);

//References to apocalypse specific items and blocks:
public static BlockItemHolder skeleton, slumpedSkeleton, gunRack;

static
{
FluidRegistry.enableUniversalBucket();
}

@SubscribeEvent
public void registerItems(RegistryEvent.Register<Item> event)
{
event.getRegistry().register(sulphur);
event.getRegistry().register(itemBlockLabStone);
event.getRegistry().register(itemBlockSulphur);
event.getRegistry().register(itemBlockPowerCube);
}

@SubscribeEvent
Expand Down Expand Up @@ -151,13 +162,16 @@ public void preInit(FMLPreInitializationEvent event)
blockSulphur = new BlockSulphur().setUnlocalizedName("blockSulphur").setRegistryName("blockSulphur").setCreativeTab(tabApocalypse);
sulphur = new Item().setUnlocalizedName("flanSulphur").setRegistryName("flanSulphur").setCreativeTab(tabApocalypse);

itemBlockSulphur = new ItemBlock(blockSulphur).setUnlocalizedName("blockSulphur").setRegistryName("itemBlockSulphur").setCreativeTab(tabApocalypse);

//Sulphuric acid
sulphuricAcid = new Fluid("sulphuricAcid", sulphuricAcidStill, sulphuricAcidFlowing).setTemperature(300).setViscosity(800);
if(FluidRegistry.registerFluid(sulphuricAcid))
{
blockSulphuricAcid = new BlockSulphuricAcid(sulphuricAcid, Material.WATER).setUnlocalizedName("blockSulphuricAcid").setRegistryName("blockSulphuricAcid").setCreativeTab(tabApocalypse);
sulphuricAcid.setBlock(blockSulphuricAcid);
sulphuricAcid.setUnlocalizedName(blockSulphuricAcid.getUnlocalizedName());
FluidRegistry.addBucketForFluid(sulphuricAcid);
}
else
{
Expand All @@ -167,9 +181,11 @@ public void preInit(FMLPreInitializationEvent event)

//Laboratory Stone
blockLabStone = new BlockStatic(Material.ROCK).setHardness(3F).setResistance(5F).setUnlocalizedName("labStone").setRegistryName("labStone").setCreativeTab(tabApocalypse);

itemBlockLabStone = new ItemBlock(blockLabStone).setUnlocalizedName("labStone").setRegistryName("itemBlockLabStone").setCreativeTab(tabApocalypse);

//Power Cube
blockPowerCube = new BlockPowerCube(Material.CIRCUITS).setUnlocalizedName("powerCube").setRegistryName("powerCube").setHardness(3F).setResistance(5F).setCreativeTab(tabApocalypse);
itemBlockPowerCube = new ItemBlock(blockPowerCube).setUnlocalizedName("powerCube").setRegistryName("itemBlockPowerCube").setCreativeTab(tabApocalypse);
GameRegistry.registerTileEntity(TileEntityPowerCube.class, "powerCube");

proxy.preInit(event);
Expand All @@ -189,15 +205,27 @@ public void init(FMLInitializationEvent event)
skeleton = ItemHolderType.getItemHolder("flanSkeleton").block;
skeleton.setCreativeTab(tabApocalypse);
}
else
{
FlansMod.log("Could not find skeleton item holder!");
}
if(ItemHolderType.getItemHolder("flanSkeleton2") != null)
{
slumpedSkeleton = ItemHolderType.getItemHolder("flanSkeleton2").block;
slumpedSkeleton.setCreativeTab(tabApocalypse);
}
else
{
FlansMod.log("Could not find skeleton2 item holder!");
}
if(ItemHolderType.getItemHolder("flanGunRack") != null)
{
gunRack = ItemHolderType.getItemHolder("flanGunRack").block;
gunRack.setCreativeTab(tabApocalypse);
}
else
{
FlansMod.log("Could not find gun rack item holder!");
}

//Put ai chip in apocalypse tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public ItemStack getRandomLoadedGun(Random rand, boolean explosivesAllowed)
}
stack.getTagCompound().setTag("ammo", ammoTagsList);
}
if(gunType.paintjobs.size() > 1)
stack.setItemDamage(rand.nextInt(gunType.paintjobs.size()));
return stack;
}

Expand Down Expand Up @@ -351,11 +353,19 @@ public void fillWeaponChest(Random rand, TileEntityChest chest)
{
for(int i = 0; i < 3 + rand.nextInt(3); i++)
{
chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory()), getRandomAmmo(rand));
ItemStack stack = getRandomAmmo(rand);
if(stack != null)
{
chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory()), stack);
}
}
for(int i = 0; i < 1 + rand.nextInt(1); i++)
{
chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory()), getRandomAttachment(rand));
ItemStack stack = getRandomAttachment(rand);
if(stack != null)
{
chest.setInventorySlotContents(rand.nextInt(chest.getSizeInventory()), stack);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,20 @@ public boolean canPlaceBlockAt(World world, BlockPos pos)
return world.getBlockState(pos.add(0, -1, 0)).isSideSolid(world, pos.add(0, -1, 0), EnumFacing.UP);
}

/*

@Override
public boolean isOpaqueCube()
public boolean isOpaqueCube(IBlockState state)
{
return false;
}

@Override
public void onEntityCollidedWithBlock(World par1World, BlockPos pos, Entity par5Entity)
{
}
protected static final AxisAlignedBB AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
@Override
public void setBlockBoundsBasedOnState(IBlockAccess access, BlockPos pos)
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1F, 1.0F);
return AABB;
}

@Override
public void setBlockBoundsForItemRender()
{
float var1 = 0.5F;
float var2 = 0.5F;
float var3 = 0.5F;
this.setBlockBounds(0.0F, 0.5F - var2, 0.0F, 1F, 0.5F + var2, 1F);
}
*/

@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fluids.BlockFluidClassic;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockSulphuricAcid extends BlockFluidClassic
{
public static final PropertyFloat HEIGHT_NW = new PropertyFloat("height_nw", 0F, 1F), HEIGHT_SW = new PropertyFloat("height_sw", 0F, 1F),
HEIGHT_SE = new PropertyFloat("height_se", 0F, 1F), HEIGHT_NE = new PropertyFloat("height_ne", 0F, 1F);
//public static final PropertyFloat FLOW_DIRECTION = new PropertyFloat("flow_direction");
public static final DamageSource acidDamage = new DamageSource("sulphuricAcid");

public BlockSulphuricAcid(Fluid fluid, Material material)
Expand All @@ -41,107 +42,9 @@ public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState sta
entity.attackEntityFrom(acidDamage, 5.0F);
}

@Override
protected BlockStateContainer createBlockState()
{
return new ExtendedBlockState(this, new IProperty[] {LEVEL}, new IUnlistedProperty[] {HEIGHT_SW, HEIGHT_NW, HEIGHT_SE, HEIGHT_NE, FLOW_DIRECTION, LEVEL_CORNERS[0], LEVEL_CORNERS[1], LEVEL_CORNERS[2], LEVEL_CORNERS[3]});
}

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
@SideOnly(Side.CLIENT)
public void registerRenderer()
{
state = super.getExtendedState(state, world, pos);

float heightNW, heightSW, heightSE, heightNE;
float flow11 = getFluidHeightForRender(world, pos);

if (flow11 != 1)
{
float flow00 = getFluidHeightForRender(world, pos.add(-1, 0, -1));
float flow01 = getFluidHeightForRender(world, pos.add(-1, 0, 0));
float flow02 = getFluidHeightForRender(world, pos.add(-1, 0, 1));
float flow10 = getFluidHeightForRender(world, pos.add( 0, 0, -1));
float flow12 = getFluidHeightForRender(world, pos.add( 0, 0, 1));
float flow20 = getFluidHeightForRender(world, pos.add( 1, 0, -1));
float flow21 = getFluidHeightForRender(world, pos.add( 1, 0, 0));
float flow22 = getFluidHeightForRender(world, pos.add( 1, 0, 1));

heightNW = getFluidHeightAverage(new float[]{ flow00, flow01, flow10, flow11 });
heightSW = getFluidHeightAverage(new float[]{ flow01, flow02, flow12, flow11 });
heightSE = getFluidHeightAverage(new float[]{ flow12, flow21, flow22, flow11 });
heightNE = getFluidHeightAverage(new float[]{ flow10, flow20, flow21, flow11 });
}
else
{
heightNW = flow11;
heightSW = flow11;
heightSE = flow11;
heightNE = flow11;
}

IExtendedBlockState extState = (IExtendedBlockState) state;
extState = extState.withProperty(HEIGHT_NW, heightNW).withProperty(HEIGHT_SW, heightSW);
extState = extState.withProperty(HEIGHT_SE, heightSE).withProperty(HEIGHT_NE, heightNE);
extState = extState.withProperty(FLOW_DIRECTION, (float) BlockFluidBase.getFlowDirection(world, pos));

return extState;
ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(LEVEL).build());
}

/*
// TODO : [1.12] Fluids?
@Override
public boolean shouldSideBeRendered(IBlockAccess world, BlockPos pos, EnumFacing side)
{
if(side == EnumFacing.UP)
return world.getBlockState(pos).getBlock() != this;
else return super.shouldSideBeRendered(world, pos, side);
}
*/

public float getFluidHeightForRender(IBlockAccess world, BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
Block verticalOrigin = world.getBlockState(pos.down(this.densityDir)).getBlock();
if (state.getBlock() == this)
{
if (state.getMaterial().isLiquid() || verticalOrigin instanceof IFluidBlock)
{
return 1;
}

if ((Integer) state.getValue(LEVEL) == this.getMaxRenderHeightMeta())
{
return 0.875F;
}
}
return !state.getMaterial().isSolid() && verticalOrigin == this ? 1 : this.getQuantaPercentage(world, pos) * 0.875F;
}

@Override
public float getFluidHeightAverage(float... height)
{
float total = 0;
int count = 0;

float end = 0;

for (int i = 0; i < height.length; i++)
{
if (height[i] >= 0.875F && end != 1F)
{
end = height[i];
}

if (height[i] >= 0)
{
total += height[i];
count++;
}
}

if (end == 0)
end = total / count;

return end;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

public class EntityFlyByPlane extends EntityPlane
{
public EntityFlyByPlane(World world)
{
super(world);
}

public EntityFlyByPlane(World world, double x, double y, double z, PlaneType type, DriveableData data)
{
super(world, x, y, z, type, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ protected void writeEntityToNBT(NBTTagCompound tags)
tags.setInteger("X", lowerLeftCornerPowerCube.getX());
tags.setInteger("Y", lowerLeftCornerPowerCube.getY());
tags.setInteger("Z", lowerLeftCornerPowerCube.getZ());
tags.setInteger("targetX", targetTeleporter.getX());
tags.setInteger("targetY", targetTeleporter.getY());
tags.setInteger("targetZ", targetTeleporter.getZ());
if(targetTeleporter != null)
{
tags.setInteger("targetX", targetTeleporter.getX());
tags.setInteger("targetY", targetTeleporter.getY());
tags.setInteger("targetZ", targetTeleporter.getZ());
}
}

}

0 comments on commit 4969858

Please sign in to comment.