mirror of
https://github.com/GTNewHorizons/StructureLib.git
synced 2026-11-19 11:49:31 +00:00
Add constructable
This commit is contained in:
1 parent
faf4c8d9ef
commit
d7c3f9b10c
8 files changed
+168
-18
No files matched your search
+74
@@ -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;
|
||||
}
|
||||
}
|
||||
+16
@@ -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);
|
||||
}
|
||||
|
||||
+14
@@ -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();
|
||||
}
|
||||
+34
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user