Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Sep 6, 2024
1 parent aa5f400 commit 18cf9dc
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ catch (Exception ignored) {

// Pulls version first from the VERSION env and then git tag
String identifiedVersion = null
String versionOverride = '0.0.18p19'
String versionOverride = '0.0.18p20'
try {
// Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty
if (versionOverride == null) {
Expand Down
93 changes: 93 additions & 0 deletions src/main/java/reobf/proghatches/block/BlockReactorSyncer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package reobf.proghatches.block;

import java.util.Random;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockReactorSyncer extends BlockContainer{

public BlockReactorSyncer(Material p_i45386_1_) {
super(p_i45386_1_);
setHardness(1);
setHarvestLevel("pickaxe", 1);
setBlockName("proghatch.reactor_syncer");
}
@Override
public boolean shouldCheckWeakPower(IBlockAccess world, int x, int y, int z, int side) {

return false;//false for all sides,in case the block gets powered and activate the reactor
}
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
switch(side){
case -1:side=1;break;
case 0:side=2;break;
case 1:side=5;break;
case 2:side=3;break;
case 3:side=4;break;
}


int meta=world.getBlockMetadata(x, y, z);
return (side==(meta^1));
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileReactorSyncer();
}
public void onBlockPlacedBy(World worldIn, int x, int y, int z, EntityLivingBase placer, ItemStack itemIn)
{
int l = BlockPistonBase.determineOrientation(worldIn, x, y, z, placer);
worldIn.setBlockMetadataWithNotify(x, y, z, l, 2);


}
@Override
public int isProvidingWeakPower(IBlockAccess worldIn, int x, int y, int z, int side) {
if(worldIn.getBlockMetadata(x, y, z)==(side)){
TileReactorSyncer te=(TileReactorSyncer) worldIn.getTileEntity(x, y, z);
return te.power();
};

return 0;
}
@Override
public void updateTick(World worldIn, int x, int y, int z, Random random) {
ForgeDirection dir=ForgeDirection.values()[worldIn.getBlockMetadata(x, y, z)].getOpposite();
worldIn.notifyBlockOfNeighborChange(x+dir.offsetX, y+dir.offsetY, z+dir.offsetZ, this);
}
@Override
public boolean getTickRandomly() {
return false;
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
if(side==(meta^1)){
return GameRegistry.findBlock("IC2", "blockReactorRedstonePort").getIcon(0,0);
}
if(side==meta){
return GameRegistry.findBlock("IC2", "blockGenerator").getIcon(ForgeDirection.UP.ordinal(), 5);
//Blocks.redstone_block.getIcon(0, 0);
}

return Blocks.iron_block.getIcon(0, 0);
}



}
43 changes: 43 additions & 0 deletions src/main/java/reobf/proghatches/block/ItemBlockReactorSyncer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package reobf.proghatches.block;

import java.util.List;
import java.util.function.Consumer;

import com.gtnewhorizons.modularui.api.KeyboardUtil;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import reobf.proghatches.lang.LangManager;

public class ItemBlockReactorSyncer extends ItemBlock {

public ItemBlockReactorSyncer(Block p_i45328_1_) {
super(p_i45328_1_);

}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_) {
int i = 0;
while (true) {
String k = "tile.reactor_syncer.tooltip";

if (LangManager.translateToLocal(k).equals(Integer.valueOf(i).toString())) {
break;
}
String key = k + "." + i;
String trans = LangManager.translateToLocal(key);

p_77624_3_.add(trans);
i++;

}
super.addInformation(p_77624_1_, p_77624_2_, p_77624_3_, p_77624_4_);
}
}
76 changes: 76 additions & 0 deletions src/main/java/reobf/proghatches/block/TileReactorSyncer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package reobf.proghatches.block;

import ic2.core.block.reactor.tileentity.TileEntityNuclearReactorElectric;
import ic2.core.block.reactor.tileentity.TileEntityReactorAccessHatch;
import ic2.core.block.reactor.tileentity.TileEntityReactorChamberElectric;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import reobf.proghatches.main.MyMod;

public class TileReactorSyncer extends TileEntity{


private boolean isDead;

@Override
public void validate() {
super.validate();
MyMod.callbacks.put(this,this::pretick);
}


public void pretick(){
if((!isDead)&&(!isInvalid())){
TileEntityNuclearReactorElectric reactor=findTarget();
if(reactor!=null) tick=reactor.updateTicker%20;

//int new_power=(tick>5&&tick<15)?15:0;
int new_power=(tick!=0)?15:0;
if(power!=new_power){

//worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);

worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, getBlockType()
, 0);
//schedule it, update it in World#tick, just in case something magic happens...
}

power=new_power;
}
}


public int power(){
if(power<0){return 0;}
return power;
}
public int tick;
public int power=-1;//ic2 reactor reset its tick value everytime world loads, so it's no point saving the value
public TileEntityNuclearReactorElectric findTarget(){

ForgeDirection dir=ForgeDirection.values()[this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord)];
TileEntity te=this.worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ);

if(te instanceof TileEntityNuclearReactorElectric)return (TileEntityNuclearReactorElectric) te;
if(te instanceof TileEntityReactorChamberElectric){
return ((TileEntityReactorChamberElectric) te).getReactor();}
if(te instanceof TileEntityReactorAccessHatch){
Object possible= ((TileEntityReactorAccessHatch) te).getReactor();
return possible instanceof TileEntityNuclearReactorElectric?(TileEntityNuclearReactorElectric)possible:null;
}
return null;
}

@Override
public void onChunkUnload() {

super.onChunkUnload();
isDead = true;
}

@Override
public void updateEntity() {
super.updateEntity();
isDead = false;
}
}
8 changes: 8 additions & 0 deletions src/main/java/reobf/proghatches/main/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
import reobf.proghatches.ae.TileCyclicPatternSubmitter;
import reobf.proghatches.block.BlockAnchorAlert;
import reobf.proghatches.block.BlockIOHub;
import reobf.proghatches.block.BlockReactorSyncer;
import reobf.proghatches.block.ItemBlockAnchorAlert;
import reobf.proghatches.block.ItemBlockIOHub;
import reobf.proghatches.block.ItemBlockReactorSyncer;
import reobf.proghatches.block.TileAnchorAlert;
import reobf.proghatches.block.TileIOHub;
import reobf.proghatches.block.TileReactorSyncer;
import reobf.proghatches.eucrafting.BlockEUInterface;
import reobf.proghatches.eucrafting.EUUtil;
import reobf.proghatches.eucrafting.ItemBlockEUInterface;
Expand Down Expand Up @@ -69,6 +72,7 @@ public void preInit(FMLPreInitializationEvent event) {
GameRegistry.registerTileEntity(TileFluidInterface_EU.class, "proghatches.euinterface");
GameRegistry.registerTileEntity(TileCyclicPatternSubmitter.class, "proghatches.submitter");
GameRegistry.registerTileEntity(TileCardReader.class, "proghatches.card_reader");
GameRegistry.registerTileEntity(TileReactorSyncer.class, "proghatches.reactor_syncer");
ItemMEPlunger a=new ItemMEPlunger(100000);


Expand Down Expand Up @@ -132,6 +136,10 @@ public void preInit(FMLPreInitializationEvent event) {

MyMod.reader = GameRegistry.registerBlock(new BlockCardReader(Material.rock),
"proghatches.card_reader");
MyMod.reactorsyncer = GameRegistry.registerBlock(new BlockReactorSyncer(Material.rock),
ItemBlockReactorSyncer.class
,
"proghatches.reactor_syncer");
li.cil.oc.server.driver.Registry.add((li.cil.oc.api.driver.Item) MyMod.oc_redstone);
li.cil.oc.server.driver.Registry.add((li.cil.oc.api.driver.Item) MyMod.oc_api);
li.cil.oc.server.driver.Registry.add((li.cil.oc.api.driver.Item) MyMod.pitem);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/reobf/proghatches/main/MyMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.Collection;
import java.util.Deque;
import java.util.Optional;
import java.util.WeakHashMap;

import javax.annotation.Nullable;

import net.minecraft.block.Block;
Expand Down Expand Up @@ -87,6 +89,8 @@
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.WorldTickEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
Expand Down Expand Up @@ -504,4 +508,12 @@ public void init(Entity entity, World world) {

}}

public static WeakHashMap<Object,Runnable> callbacks=new WeakHashMap<>();
public static Block reactorsyncer;
@SubscribeEvent(priority = EventPriority.HIGH, receiveCanceled = false)
public void pretick(final TickEvent.ServerTickEvent event) {
if(event.phase==Phase.START&&event.side==Side.SERVER){
callbacks.forEach((a,b)->b.run());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private static void wrap(TileEntity capProvider, ForgeDirection face,
CallbackInfoReturnable<InventoryAdaptor> ret, TileEntity inter) {


System.out.println(face);
Thread.dumpStack();
//System.out.println(face);
//Thread.dumpStack();
if (face == ForgeDirection.UNKNOWN) {
return;
}
Expand All @@ -56,8 +56,8 @@ private static void wrap(TileEntity capProvider, ForgeDirection face,

if (iscover || ispart) {

BlockPos pos = /*new BlockPos(capProvider.xCoord + face.offsetX, capProvider.yCoord + face.offsetY,
capProvider.zCoord + face.offsetZ);*/new BlockPos(inter);
BlockPos pos = new BlockPos(capProvider.xCoord + face.offsetX, capProvider.yCoord + face.offsetY,
capProvider.zCoord + face.offsetZ);

InventoryAdaptor item = InventoryAdaptor.getAdaptor(capProvider, face);
IFluidHandler fluid = capProvider instanceof IFluidHandler ? (IFluidHandler) capProvider : null;
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/proghatches/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,9 @@ proghatches.submitter.state.2=§aSubmitted
hatch.input.dual.oc=Programmable Dual Input Hub(ME)
tile.proghatches.card_reader.name=Sensor Card Reader
proghatch.eucrafting.warn=§cExperimental item! Disabled by default, turn on Mixin in config to make it work.
tile.reactor_syncer.tooltip.0=Output redstone signal accroding to IC2 Nuclear Reactor update ticker.
tile.reactor_syncer.tooltip.1=Helpful if you want to manipulate the Reactor inventory without halting the Reactor.
tile.reactor_syncer.tooltip.2=Note that vanilla redstone update every 2 ticks!
tile.reactor_syncer.tooltip.3=Better use Redstone P2P, Redstone Conduit or Redalloy Wire instead.
tile.reactor_syncer.tooltip=4
tile.proghatch.reactor_syncer.name=Reactor Update Synchronizer
5 changes: 5 additions & 0 deletions src/main/resources/assets/proghatches/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,8 @@ proghatches.submitter.state.2=§a已提交
hatch.input.dual.oc=可编程二合一输入枢纽(ME)
tile.proghatches.card_reader.name=传感器卡片读卡器
proghatch.eucrafting.warn=§c实验性物品 默认禁用 需要在配置中打开Mixin才能工作
tile.reactor_syncer.tooltip.0=根据IC2核反应堆更新计数器输出红石信号
tile.reactor_syncer.tooltip.1=有助于不停机情况下直接操作反应堆内容物
tile.reactor_syncer.tooltip.2=注意:原版红石每2tick更新 最好使用红石P2P,红石导管和红色合金导线
tile.reactor_syncer.tooltip=3
tile.proghatch.reactor_syncer.name=反应堆更新同步器

0 comments on commit 18cf9dc

Please sign in to comment.