-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
248 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/reobf/proghatches/block/BlockReactorSyncer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
src/main/java/reobf/proghatches/block/ItemBlockReactorSyncer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
76
src/main/java/reobf/proghatches/block/TileReactorSyncer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters