Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Plastic Block Properties #60

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/mekanism/common/MekanismBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class MekanismBlocks
public static final Block BoundingBlock = (BlockBounding)new BlockBounding().setBlockName("BoundingBlock");
public static final Block GasTank = new BlockGasTank().setBlockName("GasTank");
public static final Block CardboardBox = new BlockCardboardBox().setBlockName("CardboardBox");
public static final Block PlasticBlock = new BlockPlastic().setBlockName("PlasticBlock");
public static final Block SlickPlasticBlock = new BlockPlastic().setBlockName("SlickPlasticBlock");
public static final Block GlowPlasticBlock = new BlockPlastic().setBlockName("GlowPlasticBlock");
public static final Block ReinforcedPlasticBlock = new BlockPlastic().setBlockName("ReinforcedPlasticBlock");
public static final Block RoadPlasticBlock = new BlockPlastic().setBlockName("RoadPlasticBlock");
public static final Block PlasticBlock = new BlockPlastic("normal").setBlockName("PlasticBlock");
public static final Block SlickPlasticBlock = new BlockPlastic("slick").setBlockName("SlickPlasticBlock");
public static final Block GlowPlasticBlock = new BlockPlastic("glow").setBlockName("GlowPlasticBlock");
public static final Block ReinforcedPlasticBlock = new BlockPlastic("reinforced").setBlockName("ReinforcedPlasticBlock");
public static final Block RoadPlasticBlock = new BlockPlastic("road").setBlockName("RoadPlasticBlock");
public static final Block PlasticFence = new BlockPlasticFence().setBlockName("PlasticFence");
public static final Block SaltBlock = new BlockSalt().setBlockName("SaltBlock");

Expand Down
52 changes: 36 additions & 16 deletions src/main/java/mekanism/common/block/BlockPlastic.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
Expand All @@ -20,17 +22,14 @@

public class BlockPlastic extends Block
{
public BlockPlastic()
public BlockPlastic(String type)
{
super(Material.wood);
setHardness(this == MekanismBlocks.ReinforcedPlasticBlock ? 50F : 5F);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of this returned null everytime. You can see how that's a problem here.

setResistance(this == MekanismBlocks.ReinforcedPlasticBlock ? 2000F : 10F);
setHardness(type == "reinforced" ? 50F : 5F);
setResistance(type == "reinforced" ? 2000F : 10F);
setCreativeTab(Mekanism.tabMekanism);

if(this == MekanismBlocks.SlickPlasticBlock)
{
if (type == "slick")
slipperiness = 0.98F;
}
}

@Override
Expand Down Expand Up @@ -60,18 +59,34 @@ else if(this == MekanismBlocks.RoadPlasticBlock)
}

@Override
public void onEntityWalking(World world, int x, int y, int z, Entity e)
{
if(this == MekanismBlocks.RoadPlasticBlock)
{
double boost = 1.6;

double a = Math.atan2(e.motionX, e.motionZ);
e.motionX += Math.sin(a) * boost * slipperiness;
e.motionZ += Math.cos(a) * boost * slipperiness;
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
if (this == MekanismBlocks.RoadPlasticBlock) {
final float f = 1 / 128f;
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1 - f, z + 1);
} else {
return AxisAlignedBB.getBoundingBox((double)x + this.minX, (double)y + this.minY, (double)z + this.minZ, (double)x + this.maxX, (double)y + this.maxY, (double)z + this.maxZ);
}
}

@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity e) {
if (this == MekanismBlocks.RoadPlasticBlock) {

if (e.getEntityData().getInteger("Mekanism:road") == e.ticksExisted)
return;
e.getEntityData().setInteger("Mekanism:road", e.ticksExisted);

double boost = 0.99 * slipperiness;

final double minSpeed = 1e-9;

if (Math.abs(e.motionX) > minSpeed || Math.abs(e.motionZ) > minSpeed) {
e.motionX += e.motionX * boost;
e.motionZ += e.motionZ * boost;
}
}
}

@Override
public int damageDropped(int i)
{
Expand Down Expand Up @@ -111,6 +126,11 @@ public int getLightValue()

return 0;
}
@Override
public boolean canCreatureSpawn(EnumCreatureType type, IBlockAccess world, int x, int y, int z){

return false;
}

@Override
public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour)
Expand Down