Commit cc50f25a authored by primetoxinz's avatar primetoxinz

I actually don't know how to do this. But I'm going to commit that's here.

parent 39f6676b
......@@ -45,8 +45,12 @@ dependencies {
deobfCompile "mezz.jei:jei_1.12.2:4.8.3.128"
deobfCompile "applecore:AppleCore:1.12.2-3.1.0:deobf"
deobfCompile "team.chisel.ctm:CTM:MC1.12-0.2.3.9"
compile "MCMultiPart2:MCMultiPart:2.4.1"
runtime "MCMultiPart2:MCMultiPart:2.4.1"
}
jar {
manifest {
attributes 'FMLAT': 'bwm_at.cfg'
......
package betterwithmods.module.compat.multipart;
import betterwithmods.module.gameplay.miniblocks.ItemMini;
import betterwithmods.module.gameplay.miniblocks.MiniType;
import betterwithmods.module.gameplay.miniblocks.blocks.BlockMini;
import betterwithmods.module.gameplay.miniblocks.blocks.BlockSiding;
import mcmultipart.api.addon.IMCMPAddon;
import mcmultipart.api.addon.IWrappedBlock;
import mcmultipart.api.addon.MCMPAddon;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.multipart.IMultipartRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@MCMPAddon()
public class BWMMCMP implements IMCMPAddon {
@Override
public void registerParts(IMultipartRegistry registry) {
// MiniBlocks.MINI_MATERIAL_BLOCKS.keySet()
// for (MiniType type : Sets.newHashSet(MiniType.SIDING)) {
// for (BlockMini block : MiniBlocks.MINI_MATERIAL_BLOCKS.get(type).values()) {
// IMultipart part = fromType(block, type);
// if (part != null) {
// register(registry, block, part).setBlockPlacementLogic(this::placeSiding);
// }
// }
// }
}
private boolean placeSiding(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IBlockState newState) {
if (!stack.isEmpty() && stack.getItem() instanceof ItemMini && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(newState.getBlock(), pos, false, facing, (Entity) null)) {
if (ItemMini.placeBlockAt((ItemMini) stack.getItem(), stack, player, world, pos, facing, hitX, hitY, hitZ, newState)) {
newState = world.getBlockState(pos);
SoundType soundtype = newState.getBlock().getSoundType(newState, world, pos, player);
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
if(!player.isCreative())
stack.shrink(1);
}
return true;
}
return false;
}
public IWrappedBlock register(IMultipartRegistry registry, Block block, IMultipart proxy) {
registry.registerPartWrapper(block, proxy);
return registry.registerStackWrapper(Item.getItemFromBlock(block), i -> true, block);
}
public IMultipart fromType(BlockMini mini, MiniType type) {
switch (type) {
case SIDING:
return new MultipartSiding((BlockSiding) mini);
case MOULDING:
break;
case CORNER:
break;
case UNKNOWN:
break;
}
return null;
}
}
package betterwithmods.module.compat.multipart;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.multipart.IMultipartTile;
import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.function.Function;
public class MultipartProxy implements IMultipart {
private final Block block;
private final Function<IBlockState, IPartSlot> placementSlot, worldSlot;
public MultipartProxy(Block block, Function<IBlockState, IPartSlot> placementSlot, Function<IBlockState, IPartSlot> worldSlot) {
this.block = block;
this.placementSlot = placementSlot;
this.worldSlot = worldSlot;
}
public MultipartProxy(Block block, Function<IBlockState, IPartSlot> wrapper) {
this(block, wrapper, wrapper);
}
@Override
public Block getBlock() {
return block;
}
@Override
public IMultipartTile convertToMultipartTile(TileEntity tileEntity) {
return new MultipartTileProxy(tileEntity);
}
@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
return placementSlot.apply(state);
}
@Override
public IPartSlot getSlotFromWorld(IBlockAccess world, BlockPos pos, IBlockState state) {
return worldSlot.apply(state);
}
}
\ No newline at end of file
package betterwithmods.module.compat.multipart;
import betterwithmods.module.gameplay.miniblocks.ItemMini;
import betterwithmods.module.gameplay.miniblocks.blocks.BlockMini;
import betterwithmods.module.gameplay.miniblocks.blocks.BlockSiding;
import betterwithmods.module.gameplay.miniblocks.orientations.SidingOrientation;
import betterwithmods.module.gameplay.miniblocks.tiles.TileMini;
import mcmultipart.api.container.IPartInfo;
import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.multipart.IMultipartTile;
import mcmultipart.api.slot.EnumFaceSlot;
import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class MultipartSiding implements IMultipart {
private BlockSiding siding;
public MultipartSiding(BlockSiding siding) {
this.siding = siding;
}
@Override
public Block getBlock() {
return siding;
}
@Override
public void onPartPlacedBy(IPartInfo part, EntityLivingBase placer, ItemStack stack) {
TileMini tile = (TileMini) part.getTile().getTileEntity();
ItemMini.setNBT(tile, tile.getWorld(), stack);
}
@Override
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) {
SidingOrientation orientation = (SidingOrientation) SidingOrientation.getFromVec(new Vec3d(hitX, hitY, hitZ), facing);
return EnumFaceSlot.fromFace(orientation.getFacing());
}
@Override
public IPartSlot getSlotFromWorld(IBlockAccess world, BlockPos pos, IBlockState state) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileMini) {
BlockMini mini = (BlockMini) state.getBlock();
SidingOrientation orientation = (SidingOrientation) ((TileMini) tile).getOrientation();
return EnumFaceSlot.fromFace(orientation.getFacing());
}
return EnumFaceSlot.NORTH;
}
@Override
public IMultipartTile convertToMultipartTile(TileEntity tileEntity) {
return new MultipartTileProxy(tileEntity);
}
}
package betterwithmods.module.compat.multipart;
import mcmultipart.api.multipart.IMultipartTile;
import net.minecraft.tileentity.TileEntity;
public class MultipartTileProxy implements IMultipartTile {
private TileEntity tile;
public MultipartTileProxy(TileEntity tile) {
this.tile = tile;
}
@Override
public TileEntity getTileEntity() {
return tile;
}
}
......@@ -47,7 +47,23 @@ public class ItemMini extends ItemBlock {
return stateA != null & stateB != null && stateA.equals(stateB);
}
private void setNBT(World worldIn, BlockPos pos, ItemStack stackIn) {
public static boolean placeBlockAt(ItemMini item, ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
if (!world.setBlockState(pos, newState, 11)) return false;
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == item.block) {
setTileEntityNBT(world, player, pos, stack);
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileMini)
setNBT((TileMini) tile,world, stack);
((BlockMini) item.block).onBlockPlacedBy(world, pos, state, player, stack, side, hitX, hitY, hitZ);
if (player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, stack);
}
return true;
}
public static void setNBT(TileMini tile, World worldIn, ItemStack stackIn) {
MinecraftServer minecraftserver = worldIn.getMinecraftServer();
if (minecraftserver == null)
return;
......@@ -55,40 +71,23 @@ public class ItemMini extends ItemBlock {
NBTTagCompound data = stackIn.getSubCompound("miniblock");
if (data != null) {
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileMini) {
if (!worldIn.isRemote && tileentity.onlyOpsCanSetNbt()) {
return;
}
if (!worldIn.isRemote && tile.onlyOpsCanSetNbt()) {
return;
}
NBTTagCompound tileNBT = tileentity.writeToNBT(new NBTTagCompound());
NBTTagCompound newNBT = tileNBT.copy();
tileNBT.merge(data);
NBTTagCompound tileNBT = tile.writeToNBT(new NBTTagCompound());
NBTTagCompound newNBT = tileNBT.copy();
tileNBT.merge(data);
if (!tileNBT.equals(newNBT)) {
tileentity.readFromNBT(tileNBT);
tileentity.markDirty();
}
if (!tileNBT.equals(newNBT)) {
tile.readFromNBT(tileNBT);
tile.markDirty();
}
}
}
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
if (!world.setBlockState(pos, newState, 11)) return false;
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == this.block) {
setTileEntityNBT(world, player, pos, stack);
setNBT(world, pos, stack);
((BlockMini) this.block).onBlockPlacedBy(world, pos, state, player, stack, side, hitX, hitY, hitZ);
if (player instanceof EntityPlayerMP)
CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, stack);
}
return true;
return placeBlockAt(this, stack, player, world, pos, side, hitX, hitY, hitZ, newState);
}
@Override
......
......@@ -35,7 +35,7 @@ import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import javax.annotation.Nullable;
import java.util.Comparator;
import java.util.Optional;
import java.util.stream.Collectors;
public abstract class BlockMini extends BlockRotate implements IRenderRotationPlacement {
......@@ -49,22 +49,12 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
@Override
public float getBlockHardness(IBlockState blockState, World worldIn, BlockPos pos) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileMini) {
TileMini mini = (TileMini) tile;
return mini.getState().getBlockHardness(worldIn, pos);
}
return super.getBlockHardness(blockState, worldIn, pos);
return getTile(worldIn, pos).map(t -> t.getState().getBlockHardness(worldIn, pos)).orElse(super.getBlockHardness(blockState, worldIn, pos));
}
@Override
public float getExplosionResistance(World world, BlockPos pos, @Nullable Entity exploder, Explosion explosion) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileMini) {
TileMini mini = (TileMini) tile;
return mini.getState().getBlock().getExplosionResistance(world, pos, exploder, explosion);
}
return super.getExplosionResistance(world, pos, exploder, explosion);
return getTile(world, pos).map(t -> t.getState().getBlock().getExplosionResistance(world, pos, exploder, explosion)).orElse(super.getExplosionResistance(world, pos, exploder, explosion));
}
@Override
......@@ -75,8 +65,8 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
private int compareBlockStates(IBlockState a, IBlockState b) {
Block blockA = a.getBlock();
Block blockB = b.getBlock();
int compare = Integer.compare(Block.getIdFromBlock(blockA),Block.getIdFromBlock(blockB));
if(compare == 0)
int compare = Integer.compare(Block.getIdFromBlock(blockA), Block.getIdFromBlock(blockB));
if (compare == 0)
return Integer.compare(blockA.getMetaFromState(a), blockB.getMetaFromState(b));
else
return compare;
......@@ -108,12 +98,8 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
TileMini tile = (TileMini) world.getTileEntity(pos);
IExtendedBlockState extendedBS = (IExtendedBlockState) super.getExtendedState(state, world, pos);
if (tile != null) {
return extendedBS.withProperty(MINI_INFO, MiniCacheInfo.from(tile));
}
return extendedBS;
return getTile(world, pos).map(t -> extendedBS.withProperty(MINI_INFO, MiniCacheInfo.from(t))).orElse(extendedBS);
}
@Override
......@@ -126,15 +112,16 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
return false;
}
public Optional<TileMini> getTile(IBlockAccess world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileMini)
return Optional.of((TileMini) tile);
return Optional.empty();
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
TileEntity tile = source.getTileEntity(pos);
if (tile instanceof TileMini) {
TileMini mini = (TileMini) tile;
if (mini.getOrientation() != null)
return mini.getOrientation().getBounds();
}
return Block.FULL_BLOCK_AABB;
return getTile(source, pos).map(t -> t.getOrientation().getBounds()).orElse(Block.FULL_BLOCK_AABB);
}
......@@ -149,12 +136,7 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileMini) {
TileMini mini = (TileMini) tile;
return mini.changeOrientation(mini.getOrientation().next(), false);
}
return false;
return getTile(world, pos).map(t -> t.changeOrientation(t.getOrientation().next(), false)).orElse(false);
}
@Override
......@@ -176,12 +158,7 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
@Override
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileMini) {
TileMini mini = (TileMini) tile;
return mini.getPickBlock(null, null, state);
}
return new ItemStack(this);
return getPickBlock(state, null, worldIn, pos, null);
}
......@@ -191,7 +168,6 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
}
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
player.addStat(StatList.getBlockStats(this));
......@@ -223,7 +199,6 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
}
@Override
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
if (!worldIn.isRemote && !worldIn.restoringBlockSnapshots) {
......@@ -241,29 +216,16 @@ public abstract class BlockMini extends BlockRotate implements IRenderRotationPl
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileMini) {
TileMini mini = (TileMini) tile;
return mini.getPickBlock(player, target, state);
}
return new ItemStack(this);
return getTile(world, pos).map(t -> t.getPickBlock(player, target, state)).orElse(new ItemStack(this));
}
@Override
public int getFireSpreadSpeed(IBlockAccess world, BlockPos pos, EnumFacing face) {
TileMini tile = (TileMini) world.getTileEntity(pos);
if (tile != null) {
return tile.state.getBlock().getFireSpreadSpeed(world,pos,face);
}
return 5;
return getTile(world, pos).map(t -> t.getState().getBlock().getFireSpreadSpeed(world, pos, face)).orElse(5);
}
@Override
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
TileMini tile = (TileMini) world.getTileEntity(pos);
if (tile != null) {
return tile.state.getBlock().getFlammability(world,pos,face);
}
return 10;
return getTile(world, pos).map(t -> t.getState().getBlock().getFlammability(world, pos, face)).orElse(10);
}
}
......@@ -20,6 +20,11 @@ public interface BaseOrientation extends IStringSerializable {
public String getName() {
return "default";
}
@Override
public AxisAlignedBB getBounds() {
return Block.FULL_BLOCK_AABB;
}
};
......
......@@ -7,6 +7,7 @@ import betterwithmods.module.gameplay.miniblocks.orientations.BaseOrientation;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
......@@ -38,9 +39,14 @@ public abstract class TileMini extends TileBasic {
NBTTagCompound texture = new NBTTagCompound();
NBTUtil.writeBlockState(texture, state);
tag.setTag("texture", texture);
} else {
world.setBlockToAir(pos);
}
if (orientation != null)
if (orientation != null) {
tag.setInteger("orientation", orientation.ordinal());
} else {
world.setBlockToAir(pos);
}
return tag;
}
......@@ -48,8 +54,11 @@ public abstract class TileMini extends TileBasic {
@Override
public void readFromNBT(NBTTagCompound compound) {
if (compound.hasKey("texture"))
if (compound.hasKey("texture")) {
state = NBTUtil.readBlockState(compound.getCompoundTag("texture"));
} else {
world.setBlockToAir(pos);
}
orientation = deserializeOrientation(compound);
super.readFromNBT(compound);
}
......@@ -91,16 +100,20 @@ public abstract class TileMini extends TileBasic {
}
public BaseOrientation getOrientation() {
if (orientation == null)
return BaseOrientation.DEFAULT;
return orientation;
}
public IBlockState getState() {
if (state == null)
return Blocks.AIR.getDefaultState();
return state;
}
public ItemStack getPickBlock(EntityPlayer player, RayTraceResult target, IBlockState state) {
if (this.state != null && getBlockType() instanceof BlockMini) {
return MiniBlocks.fromParent(getBlockType(), this.state);
return MiniBlocks.fromParent(getBlockType(), this.getState());
}
return ItemStack.EMPTY;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment