Add constructable

This commit is contained in:
Glease committed 2021-05-29 14:27:54 +08:00
1 parent faf4c8d9ef
commit d7c3f9b10c
8 files changed
+168 -18

No files matched your search

@@ -12,27 +12,15 @@ public class AlignmentUtility {
public static boolean handle(EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ){
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if(tTileEntity==null || aPlayer instanceof FakePlayer) {
if (tTileEntity == null || aPlayer instanceof FakePlayer) {
return aPlayer instanceof EntityPlayerMP;
}
if (aPlayer instanceof EntityPlayerMP) {
/* TODO Make GT tile entity implement this interface and delegate all functionality to MTE
if (tTileEntity instanceof IGregTechTileEntity) {
IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity();
if (metaTE instanceof IAlignmentProvider) {
IAlignment alignment = ((IAlignmentProvider) metaTE).getAlignment();
if(aPlayer.isSneaking()){
alignment.toolSetFlip(null);
}else {
alignment.toolSetRotation(null);
}
return true;
}
} else */ if (tTileEntity instanceof IAlignmentProvider) {
IAlignment alignment = ((IAlignmentProvider) tTileEntity).getAlignment();
if(aPlayer.isSneaking()){
if (aPlayer instanceof EntityPlayerMP && tTileEntity instanceof IAlignmentProvider) {
IAlignment alignment = ((IAlignmentProvider) tTileEntity).getAlignment();
if (alignment != null) {
if (aPlayer.isSneaking()) {
alignment.toolSetFlip(null);
}else {
} else {
alignment.toolSetRotation(null);
}
return true;
@@ -1,5 +1,8 @@
package com.gtnewhorizon.structurelib.alignment;
import javax.annotation.Nullable;
public interface IAlignmentProvider {
@Nullable
IAlignment getAlignment();
}
@@ -0,0 +1,74 @@
package com.gtnewhorizon.structurelib.alignment.constructable;
import com.gtnewhorizon.structurelib.StructureLib;
import com.gtnewhorizon.structurelib.alignment.IAlignment;
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.ForgeDirection;
public class ConstructableUtility {
private ConstructableUtility() {
}
public static boolean handle(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide) {
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if (tTileEntity == null || aPlayer instanceof FakePlayer) {
return aPlayer instanceof EntityPlayerMP;
}
if (aPlayer instanceof EntityPlayerMP) {
//struct gen
if (aPlayer.isSneaking() && aPlayer.capabilities.isCreativeMode) {
if (tTileEntity instanceof IConstructableProvider) {
IConstructable constructable = ((IConstructableProvider) tTileEntity).getConstructable();
if (constructable != null) {
constructable.construct(aStack, false);
}
} else if (tTileEntity instanceof IConstructable) {
((IConstructable) tTileEntity).construct(aStack, false);
} else if (IMultiblockInfoContainer.contains(tTileEntity.getClass())) {
IMultiblockInfoContainer<TileEntity> iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass());
if (tTileEntity instanceof IAlignment) {
iMultiblockInfoContainer.construct(aStack, false, tTileEntity,
((IAlignment) tTileEntity).getExtendedFacing());
} else {
iMultiblockInfoContainer.construct(aStack, false, tTileEntity,
ExtendedFacing.of(ForgeDirection.getOrientation(aSide)));
}
}
}
return true;
} else if (StructureLib.proxy.isCurrentPlayer(aPlayer)) {//particles and text client side
//if ((!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode)) {
if (tTileEntity instanceof IConstructableProvider) {
IConstructable constructable = ((IConstructableProvider) tTileEntity).getConstructable();
if (constructable != null) {
constructable.construct(aStack, true);
StructureLib.proxy.addClientSideChatMessages(constructable.getStructureDescription(aStack));
}
} else if (tTileEntity instanceof IConstructable) {
IConstructable constructable = (IConstructable) tTileEntity;
constructable.construct(aStack, true);
StructureLib.proxy.addClientSideChatMessages(constructable.getStructureDescription(aStack));
return false;
} else if (IMultiblockInfoContainer.contains(tTileEntity.getClass())) {
IMultiblockInfoContainer<TileEntity> iMultiblockInfoContainer = IMultiblockInfoContainer.get(tTileEntity.getClass());
if (tTileEntity instanceof IAlignment) {
iMultiblockInfoContainer.construct(aStack, true, tTileEntity,
((IAlignment) tTileEntity).getExtendedFacing());
} else {
iMultiblockInfoContainer.construct(aStack, true, tTileEntity,
ExtendedFacing.of(ForgeDirection.getOrientation(aSide)));
}
StructureLib.proxy.addClientSideChatMessages(IMultiblockInfoContainer.get(tTileEntity.getClass()).getDescription(aStack));
return false;
}
}
return false;
}
}
@@ -0,0 +1,16 @@
package com.gtnewhorizon.structurelib.alignment.constructable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.item.ItemStack;
/**
* Created by Tec on 24.03.2017.
*/
public interface IConstructable {
void construct(ItemStack stackSize, boolean hintsOnly);
@SideOnly(Side.CLIENT)
String[] getStructureDescription(ItemStack stackSize);
}
@@ -0,0 +1,14 @@
package com.gtnewhorizon.structurelib.alignment.constructable;
import javax.annotation.Nullable;
/**
* Implement this interface if this tile entity MIGHT be constructable
*/
public interface IConstructableProvider {
/**
* @return null if not constructable, an instance otherwise.
*/
@Nullable
IConstructable getConstructable();
}
@@ -0,0 +1,34 @@
package com.gtnewhorizon.structurelib.alignment.constructable;
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import java.util.HashMap;
/**
* To implement IConstructable on not own TileEntities
*/
public interface IMultiblockInfoContainer<T> {
HashMap<String, IMultiblockInfoContainer<?>> MULTIBLOCK_MAP = new HashMap<>();
static <T extends TileEntity> void registerTileClass(Class<T> clazz, IMultiblockInfoContainer<?> info) {
MULTIBLOCK_MAP.put(clazz.getCanonicalName(), info);
}
@SuppressWarnings("unchecked")
static <T> IMultiblockInfoContainer<T> get(Class<?> tClass) {
return (IMultiblockInfoContainer<T>) MULTIBLOCK_MAP.get(tClass.getCanonicalName());
}
static boolean contains(Class<?> tClass) {
return MULTIBLOCK_MAP.containsKey(tClass.getCanonicalName());
}
void construct(ItemStack stackSize, boolean hintsOnly, T tileEntity, ExtendedFacing aSide);
@SideOnly(Side.CLIENT)
String[] getDescription(ItemStack stackSize);
}
@@ -4,7 +4,10 @@ import com.gtnewhorizon.structurelib.entity.fx.BlockHint;
import com.gtnewhorizon.structurelib.entity.fx.WeightlessParticleFX;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
@@ -43,4 +46,16 @@ public class ClientProxy extends CommonProxy {
return ret;
}
@Override
public void addClientSideChatMessages(String... messages) {
GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();
for (String s : messages) {
chat.printChatMessage(new ChatComponentText(s));
}
}
@Override
public boolean isCurrentPlayer(EntityPlayer player) {
return player == Minecraft.getMinecraft().thePlayer;
}
}
@@ -1,6 +1,7 @@
package com.gtnewhorizon.structurelib.proxy;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
@@ -9,4 +10,9 @@ public class CommonProxy {
public void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa){}
public void hintParticle(World w, int x, int y, int z, IIcon[] icons){}
public void hintParticle(World w, int x, int y, int z, Block block, int meta){}
public boolean isCurrentPlayer(EntityPlayer player) {
return false;
}
public void addClientSideChatMessages(String... messages){
}
}