Some stuff I did
This commit is contained in:
parent
cadf93eba7
commit
3d56bf1206
8 changed files with 159 additions and 17 deletions
|
@ -1,6 +1,5 @@
|
|||
package gregtech.api.metatileentity.factory;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import gregtech.api.GregTechAPI;
|
||||
import gregtech.api.metatileentity.IMetaTileEntity;
|
||||
import gregtech.api.metatileentity.IMetaTileEntityFactory;
|
||||
|
|
103
src/main/java/gregtech/api/util/DebugRenderer.java
Normal file
103
src/main/java/gregtech/api/util/DebugRenderer.java
Normal file
|
@ -0,0 +1,103 @@
|
|||
package gregtech.api.util;
|
||||
|
||||
import gregtech.common.blocks.MetaBlocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Mod.EventBusSubscriber
|
||||
public class DebugRenderer {
|
||||
|
||||
public static Set<BlockPos> blockPosSet = new HashSet<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderWorldLast(RenderWorldLastEvent event) {
|
||||
RenderGlobal context = event.getContext();
|
||||
float partialTicks = event.getPartialTicks();
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
WorldClient world = Minecraft.getMinecraft().world;
|
||||
|
||||
if (blockPosSet.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
||||
double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
||||
double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(-playerX, -playerY, -playerZ);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.glLineWidth(2.5F);
|
||||
|
||||
{
|
||||
blockPosSet.forEach(blockPos -> {
|
||||
double distance = MathHelper.sqrt(player.getDistanceSqToCenter(blockPos));
|
||||
if (distance > 64F) {
|
||||
return;
|
||||
}
|
||||
|
||||
AxisAlignedBB box = new AxisAlignedBB(blockPos.getX() + 0.25,
|
||||
blockPos.getY() + 0.25,
|
||||
blockPos.getZ() + 0.25,
|
||||
blockPos.getX() + 0.75,
|
||||
blockPos.getY() + 0.75,
|
||||
blockPos.getZ() + 0.75);
|
||||
RenderGlobal.drawSelectionBoundingBox(box, 0.0F, 1F, 0.0F, 0.5F);
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(blockPos);
|
||||
|
||||
if (tileEntity != null) {
|
||||
AxisAlignedBB axisAlignedBB = new AxisAlignedBB(blockPos.getX() + 0.25,
|
||||
blockPos.getY() + 0.25,
|
||||
blockPos.getZ() + 0.25,
|
||||
blockPos.getX() + 0.75,
|
||||
blockPos.getY() + 0.75,
|
||||
blockPos.getZ() + 0.75);
|
||||
RenderGlobal.drawSelectionBoundingBox(axisAlignedBB, 0.0F, 0.0F, 1F, 0.5F);
|
||||
|
||||
// ((TileEntityCableEmitter) tileEntity).outgoingConnections.forEach(connectionInfo -> {
|
||||
// RenderGlobal.drawSelectionBoundingBox(new AxisAlignedBB(connectionInfo.receiverContainer.getPos()), 0.0F, 1F, 1F, 0.5F);
|
||||
//
|
||||
// });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockPlace(BlockEvent.PlaceEvent event) {
|
||||
if (event.getPlacedBlock().getBlock() == MetaBlocks.CABLE) {
|
||||
// blockPosSet.add(event.getPos());
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onBlockBreak(BlockEvent.BreakEvent event) {
|
||||
// blockPosSet.remove(event.getPos());
|
||||
}
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ public class CommonProxy {
|
|||
GTLog.logger.info("Registering Blocks...");
|
||||
IForgeRegistry<Block> registry = event.getRegistry();
|
||||
registry.register(MACHINE);
|
||||
registry.register(CABLE);
|
||||
registry.register(BOILER_CASING);
|
||||
registry.register(METAL_CASING);
|
||||
registry.register(TURBINE_CASING);
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package gregtech.common.blocks;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import gregtech.api.capability.IEnergyContainer;
|
||||
import gregtech.api.util.DebugRenderer;
|
||||
import gregtech.common.blocks.tileentity.TileEntityCableEmitter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
|
@ -30,7 +33,6 @@ public class BlockCable extends Block implements ITileEntityProvider {
|
|||
this.cableLoss = cableLoss;
|
||||
setHardness(6.0f);
|
||||
setResistance(8.0f);
|
||||
setUnlocalizedName("cable");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,18 +91,19 @@ public class BlockCable extends Block implements ITileEntityProvider {
|
|||
}
|
||||
|
||||
private void notifyNetworkAboutRefresh(World world, BlockPos initialPos) {
|
||||
PooledMutableBlockPos currentPos = PooledMutableBlockPos.retain(initialPos);
|
||||
PooledMutableBlockPos currentPos = PooledMutableBlockPos.retain(initialPos.getX(), initialPos.getY(), initialPos.getZ());
|
||||
List<BlockPos> visited = new ArrayList<>();
|
||||
Stack<EnumFacing> moveStack = new Stack<>();
|
||||
while(true) {
|
||||
for(EnumFacing facing : EnumFacing.VALUES) {
|
||||
currentPos.move(facing);
|
||||
if (!visited.contains(currentPos)) {
|
||||
visited.add(currentPos);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
EnumFacing opposite = facing.getOpposite();
|
||||
if (!visited.contains(currentPos)) {
|
||||
visited.add(currentPos.toImmutable());
|
||||
} else {
|
||||
currentPos.move(opposite);
|
||||
continue;
|
||||
}
|
||||
if(world.getBlockState(currentPos).getBlock() instanceof BlockCable) {
|
||||
//if we are cable, move forward, and update emitter, if we has one
|
||||
TileEntityCableEmitter emitter = (TileEntityCableEmitter) world.getTileEntity(currentPos);
|
||||
|
@ -116,6 +119,7 @@ public class BlockCable extends Block implements ITileEntityProvider {
|
|||
currentPos.move(moveStack.pop());
|
||||
} else break;
|
||||
}
|
||||
DebugRenderer.blockPosSet = ImmutableSet.copyOf(visited);
|
||||
currentPos.release();
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,7 @@ public class MetaBlocks {
|
|||
|
||||
CABLE = new BlockCable(64, 2, 0);
|
||||
CABLE.setRegistryName("cable");
|
||||
CABLE.setUnlocalizedName("cable");
|
||||
CABLE.setCreativeTab(GregTechAPI.TAB_GREGTECH);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import net.minecraft.block.state.IBlockState;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.PooledMutableBlockPos;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
@ -52,7 +54,7 @@ public class TileEntityCableEmitter extends TileEntity implements IEnergyContain
|
|||
}
|
||||
}
|
||||
|
||||
private static class CachedCableEntry {
|
||||
public static class CachedCableEntry {
|
||||
public final long maxVoltage;
|
||||
public final long maxAmperage;
|
||||
public final long cableLoss;
|
||||
|
@ -104,19 +106,20 @@ public class TileEntityCableEmitter extends TileEntity implements IEnergyContain
|
|||
|
||||
public void refreshConnections() {
|
||||
this.outgoingConnections.clear();
|
||||
PooledMutableBlockPos currentPos = PooledMutableBlockPos.retain(getPos());
|
||||
PooledMutableBlockPos currentPos = PooledMutableBlockPos.retain(getPos().getX(), getPos().getY(), getPos().getZ());
|
||||
List<BlockPos> visited = new ArrayList<>();
|
||||
Stack<EnumFacing> moveStack = new Stack<>();
|
||||
Stack<CachedCableEntry> pathStack = new Stack<>();
|
||||
while(true) {
|
||||
for(EnumFacing facing : EnumFacing.VALUES) {
|
||||
currentPos.move(facing);
|
||||
if (!visited.contains(currentPos)) {
|
||||
visited.add(currentPos);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
EnumFacing opposite = facing.getOpposite();
|
||||
if (!visited.contains(currentPos)) {
|
||||
visited.add(currentPos.toImmutable());
|
||||
} else {
|
||||
currentPos.move(opposite);
|
||||
continue;
|
||||
}
|
||||
IBlockState blockStateAt = world.getBlockState(currentPos);
|
||||
if(blockStateAt.getBlock() instanceof BlockCable) {
|
||||
//if it is cable, move forward and add opposite direction to move stack
|
||||
|
@ -153,7 +156,7 @@ public class TileEntityCableEmitter extends TileEntity implements IEnergyContain
|
|||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
this.refreshConnections();
|
||||
// this.refreshConnections(); // FIXME StackOverflowError
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,7 @@ public class MetaTileEntities {
|
|||
GameRegistry.registerTileEntity(TileEntityCableEmitter.class, "gregtech_cable_emitter");
|
||||
|
||||
GregTechAPI.METATILEENTITY_REGISTRY.register(0, "mte_test", new WorkableMetaTileEntityFactory<>(BlockMachine.ToolClass.WRENCH, 1, new String[]{"test_desc"}, TestMTE.class, new GTResourceLocation("mte_test"), 1, RecipeMap.FURNACE_RECIPES));
|
||||
GregTechAPI.METATILEENTITY_REGISTRY.register(1, "mte_test_generator", new TieredMetaTileEntityFactory<>(BlockMachine.ToolClass.WRENCH, 1, new String[]{"test_desc_generator"}, TestGeneratorMTE.class, new GTResourceLocation("test_desc_generator"), 1));
|
||||
GregTechAPI.METATILEENTITY_REGISTRY.register(1, "mte_test_generator", new TieredMetaTileEntityFactory<>(BlockMachine.ToolClass.WRENCH, 1, new String[]{"test_desc_generator"}, TestGeneratorMTE.class, new GTResourceLocation("mte_test_generator"), 1));
|
||||
|
||||
BlockMachine.META_TYPE = PropertyString.create("meta_type", GregTechAPI.METATILEENTITY_REGISTRY.getKeys());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"forge_marker": 1,
|
||||
"defaults": {
|
||||
"model": "gregtech:overlay_model_orientable",
|
||||
"textures": {
|
||||
"particle": "gregtech:blocks/casings/machine_casing_fusion_2",
|
||||
"top": "gregtech:blocks/casings/machine_casing_fusion_2",
|
||||
"bottom": "gregtech:blocks/casings/machine_casing_fusion_2",
|
||||
"front": "gregtech:blocks/casings/machine_casing_fusion",
|
||||
"side": "gregtech:blocks/casings/machine_casing_fusion_2",
|
||||
"overlay_front": "gregtech:blocks/void",
|
||||
"overlay_bottom": "gregtech:blocks/void",
|
||||
"overlay_top": "gregtech:blocks/void",
|
||||
"overlay_side": "gregtech:blocks/void"
|
||||
},
|
||||
"transform": "forge:default-block"
|
||||
},
|
||||
"variants": {
|
||||
"facing": {
|
||||
"north": {},
|
||||
"south": { "y": 180 },
|
||||
"west": { "y": 270 },
|
||||
"east": { "y": 90 }
|
||||
},
|
||||
"active": {
|
||||
"true": {},
|
||||
"false": {}
|
||||
},
|
||||
"inventory": [{}]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue