Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
initial corporea inhibitor
Browse files Browse the repository at this point in the history
  • Loading branch information
quat1024 committed May 24, 2018
1 parent 1052cd0 commit 2a0ae57
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A Botania addon that adds more toys for your corporea system. Designed for manag
* Corporea Prevaricator to lie to your system about the contents of a chest
* Corporea Solidifier and Liquifier to store corporea requests as items
* A corporea index you can carry around in your hand
* Item frame tinkerer!
* Lexica Botania integration
* 1 coremod boy

Expand All @@ -19,7 +20,6 @@ A Botania addon that adds more toys for your corporea system. Designed for manag

### What's planned?

* Item frame tinkerer!
* Can i get uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh Boneless block model
* Reworking the solidifier/liquifier system a little bit
* I want to think some more about the wildcard corporea interceptor thing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class IncorporealRegistry {
BLOCKS.add(new BlockCorporeaSolidifier());
BLOCKS.add(new BlockCorporeaSparkTinkerer());
BLOCKS.add(new BlockFrameTinkerer());
BLOCKS.add(new BlockCorporeaInhibitor());

for(Block b : BLOCKS) {
ItemBlock item = new ItemBlock(b);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package quaternary.incorporeal.api;

import net.minecraft.block.state.IBlockState;
import net.minecraft.world.World;

public interface ICorporeaInhibitor {
/** If true, corporea sparks cannot connect through this block. */
boolean shouldBlockCorporea(World world, IBlockState state);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package quaternary.incorporeal.block;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import quaternary.incorporeal.Incorporeal;
import quaternary.incorporeal.api.ICorporeaInhibitor;

public class BlockCorporeaInhibitor extends Block implements ICorporeaInhibitor {
public BlockCorporeaInhibitor() {
super(Material.ROCK);

setRegistryName(new ResourceLocation(Incorporeal.MODID, "corporea_inhibitor"));
setUnlocalizedName(Incorporeal.MODID + ".corporea_inhibitor");
}

@Override
public boolean shouldBlockCorporea(World world, IBlockState state) {
return true;
}
}
60 changes: 60 additions & 0 deletions src/main/java/quaternary/incorporeal/spookyasm/Hooks.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package quaternary.incorporeal.spookyasm;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import quaternary.incorporeal.Incorporeal;
import quaternary.incorporeal.api.ICorporeaInhibitor;
import quaternary.incorporeal.block.BlockCorporeaInhibitor;
import quaternary.incorporeal.etc.ICustomWrappedInventory;
import vazkii.botania.api.corporea.*;
import vazkii.botania.common.core.helper.MathHelper;
import vazkii.botania.common.entity.EntityCorporeaSpark;

import java.util.ArrayList;
import java.util.List;

public class Hooks {
@SuppressWarnings("unused") //called through asm bullshit
Expand All @@ -22,4 +32,54 @@ public static IWrappedInventory invWrapHook(InvWithLocation inv, ICorporeaSpark

return wrap;
}

public static List<ICorporeaSpark> nearbyCorporeaSparkHook(List<ICorporeaSpark> allNearby, EntityCorporeaSpark me) {
BlockPos myPos = me.getPosition();
World world = me.world;
if(world.isRemote) return allNearby;

allNearby.removeIf(otherSpork -> {
InvWithLocation otherInventory = otherSpork.getSparkInventory();
if(otherInventory == null) return true;
BlockPos otherPos = otherInventory.pos.down();

int searchStartX = Math.min(myPos.getX(), otherPos.getX());
int searchStartY = Math.min(myPos.getY(), otherPos.getY());
int searchStartZ = Math.min(myPos.getZ(), otherPos.getZ());

int searchEndX = Math.max(myPos.getX(), otherPos.getX());
int searchEndY = Math.max(myPos.getY(), otherPos.getY());
int searchEndZ = Math.max(myPos.getZ(), otherPos.getZ());

double dist = MathHelper.pointDistanceSpace(searchStartX, searchStartY, searchStartZ, searchEndX, searchEndY, searchEndZ);

//Shit raycast THE MOVIE
double searchStepX = (searchEndX - searchStartX) / dist;
double searchStepY = (searchEndY - searchStartY) / dist;
double searchStepZ = (searchEndZ - searchStartZ) / dist;

double searchX = searchStartX;
double searchY = searchStartY;
double searchZ = searchStartZ;

Incorporeal.LOGGER.info("ADDA");
for(int i=0; i < dist; i++) {
Incorporeal.LOGGER.info("Start {} {} {} End {} {} {} Pos {} {} {}", searchStartX, searchStartY, searchStartZ, searchEndX, searchEndY, searchEndZ, searchX, searchY, searchZ);
IBlockState state = world.getBlockState(new BlockPos(searchX, searchY, searchZ));
Block block = state.getBlock();
if(block instanceof ICorporeaInhibitor) {
if(((ICorporeaInhibitor)block).shouldBlockCorporea(world, state)) return true;
}

searchX += searchStepX;
searchY += searchStepY;
searchZ += searchStepZ;
}
Incorporeal.LOGGER.info("ASDASDASDASDASDASd");

return false;
});

return allNearby;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import org.objectweb.asm.tree.*;
import quaternary.incorporeal.Incorporeal;

import java.util.Arrays;
import java.util.List;
import java.util.*;

public class IncorporealTransformer implements IClassTransformer, Opcodes {

static String internalMethodHandlerName = "vazkii.botania.common.core.handler.InternalMethodHandler";
static String entityCorporeaSparkName = "vazkii.botania.common.entity.EntityCorporeaSpark";

//these arrays are quite fast
static List<String> patches = Arrays.asList(internalMethodHandlerName);
static List<String> patches = Arrays.asList(internalMethodHandlerName, entityCorporeaSparkName);

@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
Expand All @@ -28,7 +28,12 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
patchInternalMethodHandler(node);
}

ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
if(transformedName.equals(entityCorporeaSparkName)) {
Incorporeal.LOGGER.info("Patching the corporea spark entity...");
patchEntityCorporeaSpark(node);
}

ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
node.accept(writer);

Incorporeal.LOGGER.info("Finished patching !");
Expand Down Expand Up @@ -67,6 +72,30 @@ public void patchInternalMethodHandler(ClassNode node) {
instructions.insertBefore(insertionPoint, new MethodInsnNode(INVOKESTATIC, "quaternary/incorporeal/spookyasm/Hooks", "invWrapHook", "(Lvazkii/botania/api/corporea/InvWithLocation;Lvazkii/botania/api/corporea/ICorporeaSpark;Lvazkii/botania/api/corporea/IWrappedInventory;)Lvazkii/botania/api/corporea/IWrappedInventory;", false));

instructions.insertBefore(insertionPoint, new VarInsnNode(ASTORE, 6));

return;
}
}
}

public void patchEntityCorporeaSpark(ClassNode node) {
for(MethodNode method : node.methods) {
if(method.name.equals("getNearbySparks")) {
InsnList instructions = method.instructions;

ListIterator<AbstractInsnNode> inserator = instructions.iterator();
while(inserator.hasNext()) {
AbstractInsnNode insn = inserator.next();
if(insn.getOpcode() != ARETURN) continue;

inserator.previous();
System.out.println("ASDSADASD");

inserator.add(new VarInsnNode(ALOAD, 0));
inserator.add(new MethodInsnNode(INVOKESTATIC, "quaternary/incorporeal/spookyasm/Hooks", "nearbyCorporeaSparkHook", "(Ljava/util/List;Lvazkii/botania/common/entity/EntityCorporeaSpark;)Ljava/util/List;", false));

return;
}
}
}
}
Expand Down

0 comments on commit 2a0ae57

Please sign in to comment.