Allow chisel torches to be FMP microparts

This commit is contained in:
tterrag1098 committed 2015-04-06 01:16:14 -04:00
1 parent aa03baa462
commit fd33a66d18
9 files changed
+202 -20

No files matched your search

@@ -3,6 +3,7 @@ package com.cricketcraft.chisel;
import java.io.File;
import com.cricketcraft.chisel.entity.EntityChiselSnowman;
import cpw.mods.fml.common.registry.EntityRegistry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
@@ -15,6 +16,7 @@ import org.apache.logging.log4j.Logger;
import com.cricketcraft.chisel.block.BlockCarvable;
import com.cricketcraft.chisel.compat.Compatibility;
import com.cricketcraft.chisel.compat.IMCHandler;
import com.cricketcraft.chisel.compat.fmp.FMPCompat;
import com.cricketcraft.chisel.config.Configurations;
import com.cricketcraft.chisel.init.ChiselBlocks;
import com.cricketcraft.chisel.init.ChiselTabs;
@@ -28,6 +30,7 @@ import com.cricketcraft.chisel.world.GeneratorChisel;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
@@ -122,6 +125,9 @@ public class Chisel {
Features.preInit();
PacketHandler.init();
ChiselController.INSTANCE.preInit();
if (Loader.isModLoaded("ForgeMultipart")) {
new FMPCompat().init();
}
proxy.preInit();
}
@@ -6,6 +6,7 @@ import com.cricketcraft.chisel.carving.CarvableHelper;
import com.cricketcraft.chisel.carving.CarvableVariation;
import com.cricketcraft.chisel.carving.Carving;
import com.cricketcraft.chisel.carving.CarvingGroup;
import com.cricketcraft.chisel.compat.fmp.ItemBlockChiselTorchPart;
import com.cricketcraft.chisel.config.Configurations;
import com.cricketcraft.chisel.entity.EntityBallOMoss;
import com.cricketcraft.chisel.entity.EntityCloudInABottle;
@@ -17,6 +18,7 @@ import com.cricketcraft.chisel.item.*;
import com.cricketcraft.chisel.item.chisel.ItemChisel;
import com.cricketcraft.chisel.item.chisel.ItemChisel.ChiselType;
import com.google.common.collect.Lists;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -2518,14 +2520,18 @@ public enum Features {
void addBlocks() {
Carving.chisel.addVariation("torch", Blocks.torch, 0, 0);
for (int type = 0; type < 10; type++) {
if (type == 8 || type == 9)
torch[type] = new BlockCarvableTorch().disableParticles();
else
torch[type] = new BlockCarvableTorch();
torch[type].setInformation("torch" + (type + 1));
GameRegistry.registerBlock(torch[type], "torch" + (type + 1));
Carving.chisel.addVariation("torch", torch[type], 0, (type + 1));
String name = "torch" + (type + 1);
BlockCarvableTorch t = new BlockCarvableTorch(type, name);
if (type == 8 || type == 9) {
t.disableParticles();
}
if (Loader.isModLoaded("ForgeMultipart")) {
GameRegistry.registerBlock(t, ItemBlockChiselTorchPart.class, name, t);
} else {
GameRegistry.registerBlock(t, name);
}
Carving.chisel.addVariation("torch", t, 0, (type + 1));
torches[type] = t;
}
Carving.chisel.registerOre("torch", "torch");
}
@@ -22,13 +22,16 @@ public class BlockCarvableTorch extends BlockTorch implements ICarvable {
public CarvableHelper carverHelper;
private String texLocation;
protected boolean emitsParticles = true;
public int idx;
public BlockCarvableTorch() {
public BlockCarvableTorch(int idx, String tex) {
super();
carverHelper = new CarvableHelper();
setCreativeTab(ChiselTabs.tabOtherChiselBlocks);
setLightLevel(0.9375F);
setBlockName("torch");
this.idx = idx;
this.texLocation = tex;
}
@Override
@@ -45,11 +48,7 @@ public class BlockCarvableTorch extends BlockTorch implements ICarvable {
public void registerBlockIcons(IIconRegister icon) {
this.blockIcon = icon.registerIcon(Chisel.MOD_ID + ":torch/" + texLocation);
}
public void setInformation(String textureLocation) {
this.texLocation = textureLocation;
}
public BlockCarvableTorch disableParticles() {
this.emitsParticles = false;
return this;
@@ -22,7 +22,7 @@ import com.cricketcraft.chisel.Chisel;
import com.cricketcraft.chisel.carving.CarvableVariation.CarvableVariationCTM;
import com.cricketcraft.chisel.client.render.CTM;
import com.cricketcraft.chisel.client.render.TextureSubmap;
import com.cricketcraft.chisel.compat.FMPIntegration;
import com.cricketcraft.chisel.compat.fmp.FMPIMC;
import com.cricketcraft.chisel.config.Configurations;
import com.cricketcraft.chisel.item.ItemCarvable;
import com.cricketcraft.chisel.utils.GeneralClient;
@@ -376,7 +376,7 @@ public class CarvableHelper {
public void registerVariation(String name, CarvableVariation variation, Block block, int blockMeta) {
if (block.renderAsNormalBlock() || block.isOpaqueCube() || block.isNormalCube()) {
FMPIntegration.registerFMP(block, blockMeta);
FMPIMC.registerFMP(block, blockMeta);
}
if (forbidChiseling)
@@ -0,0 +1,44 @@
package com.cricketcraft.chisel.compat.fmp;
import com.cricketcraft.chisel.init.ChiselBlocks;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.MultiPartRegistry.IPartConverter;
import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
public class FMPCompat implements IPartFactory, IPartConverter {
public void init() {
MultiPartRegistry.registerConverter(this);
MultiPartRegistry.registerParts(this, new String[] { "chisel_torch" });
}
@Override
public Iterable<Block> blockTypes() {
return Lists.newArrayList(ChiselBlocks.torches);
}
@Override
public TMultiPart convert(World world, BlockCoord bc) {
Block block = world.getBlock(bc.x, bc.y, bc.z);
for (int i = 0; i < ChiselBlocks.torches.length; i++) {
if (block == ChiselBlocks.torches[i]) {
return new PartChiselTorch(i, world.getBlockMetadata(bc.x, bc.y, bc.z));
}
}
return null;
}
@Override
public TMultiPart createPart(String type, boolean client) {
if (type.equals("chisel_torch")) {
return new PartChiselTorch();
}
return null;
}
}
@@ -1,10 +1,10 @@
package com.cricketcraft.chisel.compat;
package com.cricketcraft.chisel.compat.fmp;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.event.FMLInterModComms;
public class FMPIntegration {
public class FMPIMC {
public static void registerFMP(Block block) {
registerFMP(block, 0, 15);
@@ -0,0 +1,69 @@
package com.cricketcraft.chisel.compat.fmp;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import codechicken.multipart.minecraft.TorchPart;
import com.cricketcraft.chisel.block.BlockCarvableTorch;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemBlockChiselTorchPart extends ItemBlock {
private BlockCarvableTorch torch;
// Blame FML for the duped params, these references will always be the same
public ItemBlockChiselTorchPart(Block block, BlockCarvableTorch torch) {
super(block);
this.torch = torch;
}
@SideOnly(Side.CLIENT)
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) {
return (placePart(world, new BlockCoord(x, y, z).offset(side), stack, side, false)) || (super.func_150936_a(world, x, y, z, side, player, stack));
}
public TMultiPart createMultiPart(World world, BlockCoord pos, ItemStack item, int side) {
return new PartChiselTorch(torch.idx, TorchPart.sideMetaMap[side ^ 1]);
}
public boolean placePart(World world, BlockCoord pos, ItemStack item, int side, boolean doPlace) {
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
if (tile == null) {
return false;
}
TMultiPart part = createMultiPart(world, pos, item, side);
if (part == null) {
return false;
}
if (tile.canAddPart(part)) {
if (doPlace) {
TileMultipart.addPart(world, pos, part);
}
return true;
}
return false;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
Block block = world.getBlock(x, y, z);
BlockCoord pos = new BlockCoord(x, y, z);
if (!block.isReplaceable(world, x, y, z)) {
pos = new BlockCoord(x, y, z).offset(side);
}
if (placePart(world, pos, stack, side, !world.isRemote)) {
world.playSoundEffect(pos.x + 0.5F, pos.y + 0.5F, pos.z + 0.5F, field_150939_a.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
stack.stackSize -= 1;
return true;
}
return super.onItemUse(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
}
@@ -0,0 +1,56 @@
package com.cricketcraft.chisel.compat.fmp;
import com.cricketcraft.chisel.init.ChiselBlocks;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.multipart.minecraft.TorchPart;
public class PartChiselTorch extends TorchPart {
private int idx;
public PartChiselTorch() {
}
public PartChiselTorch(int idx, int meta) {
super(meta);
this.idx = idx;
}
@Override
public void writeDesc(MCDataOutput packet) {
super.writeDesc(packet);
packet.writeInt(idx);
}
@Override
public void readDesc(MCDataInput packet) {
super.readDesc(packet);
this.idx = packet.readInt();
}
@Override
public void save(NBTTagCompound tag) {
super.save(tag);
tag.setInteger("idx", idx);
}
@Override
public void load(NBTTagCompound tag) {
super.load(tag);
this.idx = tag.getInteger("idx");
}
@Override
public Block getBlock() {
return ChiselBlocks.torches[idx];
}
@Override
public String getType() {
return "chisel_torch";
}
}
@@ -1,9 +1,11 @@
package com.cricketcraft.chisel.init;
import net.minecraft.block.Block;
import com.cricketcraft.chisel.Chisel;
import com.cricketcraft.chisel.block.*;
import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder;
import net.minecraft.block.Block;
@ObjectHolder(Chisel.MOD_ID)
public final class ChiselBlocks {
@@ -103,7 +105,7 @@ public final class ChiselBlocks {
public static BlockCarvableIceStairs[] iceStairs = new BlockCarvableIceStairs[8];
public static BlockCarvablePackedIceStairs[] packediceStairs = new BlockCarvablePackedIceStairs[8];
public static BlockCarvableTorch[] torch = new BlockCarvableTorch[16];
public static Block[] torches = new BlockCarvableTorch[16];
public static BlockCarvable[] planks = new BlockCarvable[6];