mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-22 04:52:14 +00:00
- Init: Node Manipulator Multiblock
This commit is contained in:
1 parent
ff25c1dec6
commit
aa0d63e3c6
6 files changed
+233
-10
No files matched your search
@@ -4,9 +4,9 @@ import makeo.gadomancy.client.renderers.block.BlockNodeManipulatorRenderer;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import thaumcraft.client.renderers.tile.TileWandPedestalRenderer;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
@@ -16,9 +16,11 @@ import org.lwjgl.opengl.GL11;
|
||||
* <p/>
|
||||
* Created by makeo @ 27.10.2015 15:19
|
||||
*/
|
||||
public class RenderTileNodeManipulator extends TileEntitySpecialRenderer {
|
||||
public class RenderTileNodeManipulator extends TileWandPedestalRenderer {
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partitalTicks) {
|
||||
super.renderTileEntityAt(tile, x, y, z, partitalTicks);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
|
||||
GL11.glTranslated(x, y, z);
|
||||
|
||||
@@ -4,15 +4,20 @@ import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.registration.RegisteredRecipes;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.api.ThaumcraftApiHelper;
|
||||
import thaumcraft.common.blocks.BlockStoneDevice;
|
||||
import thaumcraft.common.tiles.TileWandPedestal;
|
||||
import thaumcraft.common.items.wands.ItemWandCasting;
|
||||
import thaumcraft.common.lib.utils.InventoryUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,7 +26,7 @@ import java.util.List;
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 26.10.2015 19:23
|
||||
*/
|
||||
public class BlockNodeManipulator extends BlockStoneDevice {
|
||||
@@ -52,7 +57,7 @@ public class BlockNodeManipulator extends BlockStoneDevice {
|
||||
//TC stuff...
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
if(metadata == 5)
|
||||
if (metadata == 5)
|
||||
return new TileNodeManipulator();
|
||||
return null;
|
||||
}
|
||||
@@ -62,7 +67,7 @@ public class BlockNodeManipulator extends BlockStoneDevice {
|
||||
int ret = super.getComparatorInputOverride(world, x, y, z, rs);
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te != null && te instanceof TileWandPedestal) return 0;
|
||||
if (te != null && te instanceof TileNodeManipulator) return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -71,12 +76,65 @@ public class BlockNodeManipulator extends BlockStoneDevice {
|
||||
par3List.add(new ItemStack(par1, 1, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World world, int x, int y, int z) {
|
||||
return world.getBlock(x, y + 1, z) == Blocks.air && super.canPlaceBlockAt(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block par5) {
|
||||
if(world.getBlock(x, y + 1, z) != Blocks.air) {
|
||||
dropBlockAsItem(world, x, y, z, 5, 0);
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
super.onNeighborBlockChange(world, x, y, z, par5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float par7, float par8, float par9) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if(world.isRemote) return true;
|
||||
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
//TODO DO!
|
||||
return super.onBlockActivated(world, x, y, z, player, side, par7, par8, par9);
|
||||
if (te != null && te instanceof TileNodeManipulator && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemWandCasting) {
|
||||
TileNodeManipulator manipulator = (TileNodeManipulator) te;
|
||||
manipulator.checkMultiblock();
|
||||
if (manipulator.isMultiblockStructurePresent()) {
|
||||
if (manipulator.isInMultiblock()) {
|
||||
return tryAddWand(manipulator, x, y, z, player);
|
||||
} else if (ThaumcraftApiHelper.consumeVisFromWandCrafting(player.getCurrentEquippedItem(), player, RegisteredRecipes.costsNodeManipulatorMultiblock, true)) {
|
||||
manipulator.formMultiblock();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean tryAddWand(TileNodeManipulator manipulator, int x, int y, int z, EntityPlayer player) {
|
||||
World world = manipulator.getWorldObj();
|
||||
if (manipulator.getStackInSlot(0) != null) {
|
||||
InventoryUtils.dropItemsAtEntity(world, x, y, z, player);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
manipulator.markDirty();
|
||||
world.playSoundEffect(x, y, z, "random.pop", 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 1.5F);
|
||||
return true;
|
||||
}
|
||||
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemWandCasting) {
|
||||
ItemStack i = player.getCurrentEquippedItem().copy();
|
||||
i.stackSize = 1;
|
||||
manipulator.setInventorySlotContents(0, i);
|
||||
player.getCurrentEquippedItem().stackSize -= 1;
|
||||
if (player.getCurrentEquippedItem().stackSize == 0) {
|
||||
player.setCurrentItemOrArmor(0, null);
|
||||
}
|
||||
player.inventory.markDirty();
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
manipulator.markDirty();
|
||||
world.playSoundEffect(x, y, z, "random.pop", 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 1.6F);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package makeo.gadomancy.common.blocks.tiles;
|
||||
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import makeo.gadomancy.common.registration.RegisteredMultiblocks;
|
||||
import makeo.gadomancy.common.utils.MultiblockHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.aspects.IAspectContainer;
|
||||
import thaumcraft.api.wands.IWandable;
|
||||
import thaumcraft.common.lib.utils.InventoryUtils;
|
||||
import thaumcraft.common.tiles.TileWandPedestal;
|
||||
|
||||
/**
|
||||
@@ -20,13 +27,57 @@ import thaumcraft.common.tiles.TileWandPedestal;
|
||||
*/
|
||||
public class TileNodeManipulator extends TileWandPedestal implements IAspectContainer, IWandable {
|
||||
|
||||
public TileNodeManipulator() {
|
||||
private int ticksExisted = 0;
|
||||
private boolean multiblockStructurePresent = false;
|
||||
private boolean isMultiblock = false;
|
||||
|
||||
public TileNodeManipulator() {
|
||||
System.out.println("created..");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
ticksExisted++;
|
||||
|
||||
if(isInMultiblock() && ticksExisted % 8 == 0 && !worldObj.isRemote) {
|
||||
System.out.println("check: " + checkMultiblock());
|
||||
if(!isMultiblockStructurePresent()) {
|
||||
breakMultiblock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void breakMultiblock() {
|
||||
|
||||
//bb wand
|
||||
if(getStackInSlot(0) != null)
|
||||
InventoryUtils.dropItems(worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public void formMultiblock() {
|
||||
MultiblockHelper.MultiblockPattern toBuild = RegisteredMultiblocks.completeNodeManipulatorMultiblock;
|
||||
for(Vec3 v : toBuild.keySet()) {
|
||||
MultiblockHelper.BlockInfo info = toBuild.get(v);
|
||||
if(info.block == RegisteredBlocks.blockNode || info.block == Blocks.air) continue;
|
||||
int absX = (int) (v.xCoord + xCoord);
|
||||
int absY = (int) (v.yCoord + yCoord);
|
||||
int absZ = (int) (v.zCoord + zCoord);
|
||||
worldObj.setBlock(absX, absY, absZ, Blocks.air, 0, 0);
|
||||
worldObj.setBlock(absX, absY, absZ, info.block, info.meta, 0);
|
||||
worldObj.markBlockForUpdate(absX, absY, absZ);
|
||||
}
|
||||
TileManipulatorPillar pillar = (TileManipulatorPillar) worldObj.getTileEntity(xCoord + 1, yCoord, zCoord + 1);
|
||||
pillar.orientation = 1;
|
||||
pillar.markDirty();
|
||||
pillar = (TileManipulatorPillar) worldObj.getTileEntity(xCoord - 1, yCoord, zCoord + 1);
|
||||
pillar.orientation = 2;
|
||||
pillar.markDirty();
|
||||
pillar = (TileManipulatorPillar) worldObj.getTileEntity(xCoord - 1, yCoord, zCoord - 1);
|
||||
pillar.orientation = 3;
|
||||
pillar.markDirty();
|
||||
markDirty();
|
||||
this.isMultiblock = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +94,33 @@ public class TileNodeManipulator extends TileWandPedestal implements IAspectCont
|
||||
|
||||
}
|
||||
|
||||
public boolean isInMultiblock() {
|
||||
return isMultiblock;
|
||||
}
|
||||
|
||||
public boolean isMultiblockStructurePresent() {
|
||||
return multiblockStructurePresent;
|
||||
}
|
||||
|
||||
public boolean checkMultiblock() {
|
||||
boolean prevState = isMultiblockStructurePresent();
|
||||
MultiblockHelper.MultiblockPattern patternToCheck;
|
||||
if(prevState) { //If there is already a multiblock formed...
|
||||
if(isInMultiblock()) { //If we were actually in multiblock before
|
||||
patternToCheck = RegisteredMultiblocks.completeNodeManipulatorMultiblock;
|
||||
} else { //If we were'nt in multiblock eventhough it would be possible.
|
||||
patternToCheck = RegisteredMultiblocks.incompleteNodeManipulatorMultiblock;
|
||||
}
|
||||
this.multiblockStructurePresent = MultiblockHelper.isMultiblockPresent(worldObj, xCoord, yCoord, zCoord, patternToCheck);
|
||||
} else { //If there was no multiblock formed before..
|
||||
patternToCheck = RegisteredMultiblocks.incompleteNodeManipulatorMultiblock;
|
||||
this.multiblockStructurePresent = MultiblockHelper.isMultiblockPresent(worldObj, xCoord, yCoord, zCoord, patternToCheck);
|
||||
}
|
||||
return isMultiblockStructurePresent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public AspectList getAspects() {
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package makeo.gadomancy.common.registration;
|
||||
|
||||
import makeo.gadomancy.common.utils.MultiblockHelper;
|
||||
import net.minecraft.init.Blocks;
|
||||
import thaumcraft.common.config.ConfigBlocks;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 27.10.2015 14:05
|
||||
*/
|
||||
public class RegisteredMultiblocks {
|
||||
|
||||
public static final MultiblockHelper.MultiblockPattern incompleteNodeManipulatorMultiblock = new MultiblockHelper.MultiblockPattern(RegisteredBlocks.blockNodeManipulator, 5)
|
||||
.addBlock(0, 2, 0, RegisteredBlocks.blockNode, 0).addBlock(0, 1, 0, Blocks.air, 0)
|
||||
.addBlock(1, 0, 1, ConfigBlocks.blockCosmeticSolid, 15).addBlock(-1, 0, 1, ConfigBlocks.blockCosmeticSolid, 15).addBlock(-1, 0, -1, ConfigBlocks.blockCosmeticSolid, 15).addBlock(1, 0, -1, ConfigBlocks.blockCosmeticSolid, 15)
|
||||
.addBlock(1, 1, 1, ConfigBlocks.blockCosmeticSolid, 11).addBlock(-1, 1, 1, ConfigBlocks.blockCosmeticSolid, 11).addBlock(-1, 1, -1, ConfigBlocks.blockCosmeticSolid, 11).addBlock(1, 1, -1, ConfigBlocks.blockCosmeticSolid, 11);
|
||||
//.addBlock(1, 2, 1, ConfigBlocks.blockCrystal, 6).addBlock(-1, 2, 1, ConfigBlocks.blockCrystal, 6).addBlock(-1, 2, -1, ConfigBlocks.blockCrystal, 6).addBlock(1, 2, -1, ConfigBlocks.blockCrystal, 6);
|
||||
|
||||
public static final MultiblockHelper.MultiblockPattern completeNodeManipulatorMultiblock = new MultiblockHelper.MultiblockPattern(RegisteredBlocks.blockNodeManipulator, 5)
|
||||
.addBlock(0, 2, 0, RegisteredBlocks.blockNode, 0).addBlock(0, 1, 0, Blocks.air, 0)
|
||||
.addBlock(1, 0, 1, RegisteredBlocks.blockStoneMachine, 15).addBlock(-1, 0, 1, RegisteredBlocks.blockStoneMachine, 15).addBlock(-1, 0, -1, RegisteredBlocks.blockStoneMachine, 15).addBlock(1, 0, -1, RegisteredBlocks.blockStoneMachine, 15)
|
||||
.addBlock(1, 1, 1, RegisteredBlocks.blockStoneMachine, 11).addBlock(-1, 1, 1, RegisteredBlocks.blockStoneMachine, 11).addBlock(-1, 1, -1, RegisteredBlocks.blockStoneMachine, 11).addBlock(1, 1, -1, RegisteredBlocks.blockStoneMachine, 11);
|
||||
|
||||
}
|
||||
@@ -31,6 +31,8 @@ import java.util.List;
|
||||
public class RegisteredRecipes {
|
||||
private RegisteredRecipes() {}
|
||||
|
||||
public static AspectList costsNodeManipulatorMultiblock = new AspectList().add(Aspect.FIRE, 100).add(Aspect.WATER, 100).add(Aspect.EARTH, 100).add(Aspect.AIR, 100).add(Aspect.ORDER, 100).add(Aspect.ENTROPY, 100);
|
||||
|
||||
public static InfusionRecipe recipeGolemSilverwood;
|
||||
public static InfusionRecipe[] recipesGolemRunicShield;
|
||||
public static InfusionRecipe recipeGolemCoreBreak;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package makeo.gadomancy.common.utils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 27.10.2015 13:56
|
||||
*/
|
||||
public class MultiblockHelper {
|
||||
|
||||
public static boolean isMultiblockPresent(World world, int x, int y, int z, MultiblockPattern pattern) {
|
||||
for(Vec3 vec : pattern.keySet()) {
|
||||
BlockInfo expected = pattern.get(vec);
|
||||
Block realBlock = world.getBlock(x + (int) vec.xCoord, y + (int) vec.yCoord, z + (int) vec.zCoord);
|
||||
int realMeta = world.getBlockMetadata(x + (int) vec.xCoord, y + (int) vec.yCoord, z + (int) vec.zCoord);
|
||||
if(expected.block != realBlock || expected.meta != realMeta) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class MultiblockPattern extends LinkedHashMap<Vec3, BlockInfo> {
|
||||
|
||||
public MultiblockPattern(Block originBlock, int originMeta) {
|
||||
put(createIntVec3(0, 0, 0), new BlockInfo(originBlock, originMeta));
|
||||
}
|
||||
|
||||
public MultiblockPattern addBlock(int relativeX, int relativeY, int relativeZ, Block expectedBlock, int expectedMeta) {
|
||||
put(createIntVec3(relativeX, relativeY, relativeZ), new BlockInfo(expectedBlock, expectedMeta));
|
||||
return this;
|
||||
}
|
||||
|
||||
private Vec3 createIntVec3(int x, int y, int z) {
|
||||
return Vec3.createVectorHelper(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class BlockInfo {
|
||||
public Block block;
|
||||
public int meta;
|
||||
|
||||
private BlockInfo(Block block, int meta) {
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user