Skip to content

Commit

Permalink
Missed an important RBMK feature
Browse files Browse the repository at this point in the history
Signed-off-by: Drillgon Chickens <drillgon200@gmail.com>
  • Loading branch information
Drillgon200 committed Sep 29, 2021
1 parent 313b2a3 commit 6ee3cfa
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.6.1a"
version = "1.6.3a"
group = "com.hbm" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "hbm"

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/hbm/blocks/generic/BMPowerBox.java
Expand Up @@ -72,6 +72,8 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
boolean oldIsOn = state.getValue(IS_ON);
worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), HBMSoundHandler.reactorStart, SoundCategory.BLOCKS, 1, oldIsOn ? 0.9F : 1);
worldIn.setBlockState(pos, state.withProperty(IS_ON, !oldIsOn));
worldIn.notifyNeighborsOfStateChange(pos, this, false);
worldIn.notifyNeighborsOfStateChange(pos.offset(state.getValue(FACING).getOpposite()), this, false);
box = (TileEntityBMPowerBox)worldIn.getTileEntity(pos);
box.ticksPlaced = worldIn.getTotalWorldTime();
ControlEventSystem.get(worldIn).broadcastToSubscribed(box, ControlEvent.newEvent("lever_toggle").setVar("isOn", !oldIsOn));
Expand All @@ -82,6 +84,11 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
return true;
}

@Override
public boolean canProvidePower(IBlockState state){
return true;
}

@Override
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side){
return blockState.getValue(IS_ON) ? 15 : 0;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/hbm/blocks/generic/BlockControlPanel.java
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.RenderGlobal;
Expand Down Expand Up @@ -94,6 +95,11 @@ public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, Bloc
}
}

@Override
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face){
return BlockFaceShape.UNDEFINED;
}

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand){
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/hbm/blocks/generic/BlockDoorGeneric.java
Expand Up @@ -7,6 +7,7 @@
import com.hbm.tileentity.DoorDecl;
import com.hbm.tileentity.TileEntityDoorGeneric;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -86,6 +87,21 @@ public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entityIn, isActualState);
}

@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos){
if(!world.isRemote){
int[] corePos = findCore(world, pos.getX(), pos.getY(), pos.getZ());
if(corePos != null){
TileEntity core = world.getTileEntity(new BlockPos(corePos[0], corePos[1], corePos[2]));
if(core instanceof TileEntityDoorGeneric){
TileEntityDoorGeneric door = (TileEntityDoorGeneric)core;
door.updateRedstonePower(pos);
}
}
}
super.neighborChanged(state, world, pos, blockIn, fromPos);
}

@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos){
int meta = state.getValue(META);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/hbm/blocks/machine/rbmk/RBMKBase.java
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
Expand Down Expand Up @@ -169,6 +170,8 @@ public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, En
}

world.setBlockState(new BlockPos(pos[0], pos[1], pos[2]), this.getDefaultState().withProperty(META, DIR_NO_LID.ordinal() + BlockDummyable.offset), 3);
NBTTagCompound nbt = rbmk.writeToNBT(new NBTTagCompound());
world.getTileEntity(new BlockPos(pos[0], pos[1], pos[2])).readFromNBT(nbt);
}

return true;
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/hbm/entity/effect/EntityBlackHole.java
@@ -1,6 +1,8 @@
package com.hbm.entity.effect;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.hbm.entity.projectile.EntityRubble;
import com.hbm.interfaces.IConstantRenderer;
Expand Down Expand Up @@ -65,11 +67,13 @@ public void onUpdate() {
int y0 = (int)(this.posY + (vec.yCoord * i));
int z0 = (int)(this.posZ + (vec.zCoord * i));

if(world.getBlockState(new BlockPos(x0, y0, z0)).getMaterial().isLiquid()) {
world.setBlockState(new BlockPos(x0, y0, z0), Blocks.AIR.getDefaultState());
BlockPos des = new BlockPos(x0, y0, z0);

if(world.getBlockState(des).getMaterial().isLiquid()) {
world.setBlockState(des, Blocks.AIR.getDefaultState());
}

if(world.getBlockState(new BlockPos(x0, y0, z0)).getBlock() != Blocks.AIR) {
if(world.getBlockState(des).getBlock() != Blocks.AIR) {
EntityRubble rubble = new EntityRubble(world);
rubble.posX = x0 + 0.5F;
rubble.posY = y0;
Expand All @@ -79,7 +83,7 @@ public void onUpdate() {

world.spawnEntity(rubble);

world.setBlockState(new BlockPos(x0, y0, z0), Blocks.AIR.getDefaultState());
world.setBlockState(des, Blocks.AIR.getDefaultState());
break;
}
}
Expand Down
Expand Up @@ -94,6 +94,8 @@ public static void init(){
register(new ControlEvent("turret_set_target").setVar("players", false).setVar("passive", false).setVar("hostile", true).setVar("machines", true));
register(new ControlEvent("turret_switch").setVar("isOn", true));
register(new ControlEvent("lever_toggle").setVar("isOn", false));
register(new ControlEvent("spinny_light_power").setVar("isOn", false));
register(new ControlEvent("siren_set_state").setVar("isOn", false));
register(new ControlEvent("ctrl_button_press"));
register(new ControlEvent("initialize"));
}
Expand Down
Expand Up @@ -26,6 +26,8 @@ public class ControlEventSystem {
private Map<BlockPos, Set<IControllable>> positionSubscriptions = new HashMap<>();

public void addControllable(IControllable c){
if(allControllables.contains(c))
return;
for(String s : c.getInEvents()){
if(s.equals("tick")){
tickables.add(c);
Expand Down Expand Up @@ -58,14 +60,16 @@ public void subscribeTo(IControllable subscriber, IControllable target){
if(!positionSubscriptions.containsKey(target.getControlPos())){
positionSubscriptions.put(target.getControlPos(), new HashSet<>());
}
positionSubscriptions.get(target.getControlPos()).add(subscriber);
if(!positionSubscriptions.get(target).contains(subscriber))
positionSubscriptions.get(target.getControlPos()).add(subscriber);
}

public void subscribeTo(IControllable subscriber, BlockPos target){
if(!positionSubscriptions.containsKey(target)){
positionSubscriptions.put(target, new HashSet<>());
}
positionSubscriptions.get(target).add(subscriber);
if(!positionSubscriptions.get(target).contains(subscriber))
positionSubscriptions.get(target).add(subscriber);
}

public void unsubscribeFrom(IControllable subscriber, IControllable target){
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/hbm/inventory/gui/GUIMachineSiren.java
Expand Up @@ -49,6 +49,7 @@ protected void drawGuiContainerForegroundLayer(int i, int j) {

@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
super.drawDefaultBackground();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/hbm/items/machine/ItemRBMKLid.java
@@ -1,17 +1,15 @@
package com.hbm.items.machine;

import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.machine.rbmk.RBMKBase;
import com.hbm.items.ModItems;
import com.hbm.tileentity.machine.rbmk.TileEntityRBMKBase;

import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
Expand All @@ -33,7 +31,7 @@ public ItemRBMKLid(String s){
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos bpos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
Block b = world.getBlockState(bpos).getBlock();

if(b instanceof RBMKBase) {
if(!world.isRemote && b instanceof RBMKBase) {
RBMKBase rbmk = (RBMKBase) b;

int[] pos = rbmk.findCore(world, bpos.getX(), bpos.getY(), bpos.getZ());
Expand Down Expand Up @@ -61,6 +59,9 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos bpo
}

world.setBlockState(new BlockPos(pos[0], pos[1], pos[2]), world.getBlockState(new BlockPos(pos[0], pos[1], pos[2])).withProperty(BlockDummyable.META, meta + RBMKBase.offset), 3);
NBTTagCompound nbt = tile.writeToNBT(new NBTTagCompound());
world.getTileEntity(new BlockPos(pos[0], pos[1], pos[2])).readFromNBT(nbt);

player.getHeldItem(hand).shrink(1);

return EnumActionResult.SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/hbm/lib/RefStrings.java
Expand Up @@ -3,7 +3,7 @@
public class RefStrings {
public static final String MODID = "hbm";
public static final String NAME = "Hbm's Nuclear Tech Mod";
public static final String VERSION = "hbm-1.6.1A-1.12.2";
public static final String VERSION = "hbm-1.6.3A-1.12.2";
//HBM's Beta Naming Convention:
//V T (X)
//V -> next release version
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/hbm/particle/ParticleRadiationFog.java
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialT
this.particleRed = 0.85F;
this.particleGreen = 0.9F;
this.particleBlue = 0.5F;
this.particleAlpha = alpha;
this.particleAlpha = MathHelper.clamp(alpha, 0, 1);

Random rand = new Random(50);

Expand Down
Expand Up @@ -31,6 +31,9 @@ public void render(TileEntitySpinnyLight te, double x, double y, double z, float
coneMeshes = new int[EnumDyeColor.values().length];
for(int i = 0; i < coneMeshes.length; i ++){
float[] color = EnumDyeColor.values()[i].getColorComponentValues();
if(EnumDyeColor.values()[i] == EnumDyeColor.RED){
color = new float[]{1, 0, 0};
}
coneMeshes[i] = generateConeMesh(5, 3, 12, color[0], color[1], color[2]);
}
}
Expand Down Expand Up @@ -61,6 +64,9 @@ public void render(TileEntitySpinnyLight te, double x, double y, double z, float
GlStateManager.enableBlend();
GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, powered ? DestFactor.ONE : DestFactor.ONE_MINUS_SRC_ALPHA);
float[] color = te.color.getColorComponentValues();
if(te.color == EnumDyeColor.RED){
color = new float[]{1, 0, 0};
}
GlStateManager.color(color[0], color[1], color[2], 0.61F);
ResourceManager.spinny_light.renderPart("dome");
GL11.glPopMatrix();
Expand Down
56 changes: 52 additions & 4 deletions src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java
@@ -1,7 +1,9 @@
package com.hbm.tileentity;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.generic.BlockDoorGeneric;
Expand All @@ -11,7 +13,6 @@
import com.hbm.inventory.control_panel.DataValueFloat;
import com.hbm.inventory.control_panel.IControllable;
import com.hbm.lib.ForgeDirection;
import com.hbm.lib.HBMSoundHandler;
import com.hbm.main.MainRegistry;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.TEDoorAnimationPacket;
Expand All @@ -38,8 +39,9 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements ITi
public DoorDecl doorType;
public int openTicks = 0;
public long animStartTime = 0;
public boolean redstoned = false;
public int redstonePower;
public boolean shouldUseBB = false;
public Set<BlockPos> activatedBlocks = new HashSet<>(4);

private AudioWrapper audio;
private AudioWrapper audio2;
Expand Down Expand Up @@ -139,6 +141,15 @@ public void update(){
broadcastControlEvt();
}
PacketDispatcher.wrapper.sendToAllAround(new TEDoorAnimationPacket(pos, state, (byte)(shouldUseBB ? 1 : 0)), new TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 100));

if(redstonePower == -1 && state == 0){
tryToggle(-1);
} else if(redstonePower > 0 && state == 1){
tryToggle(-1);
}
if(redstonePower == -1){
redstonePower = 0;
}
}
}

Expand All @@ -160,6 +171,10 @@ public void onLoad(){
}

public boolean tryToggle(EntityPlayer player){
if(state == 0 && redstonePower > 0){
//Redstone "power locks" doors, just like minecraft iron doors
return false;
}
if(this.state == 0) {
if(!world.isRemote && canAccess(player)) {
this.state = 3;
Expand Down Expand Up @@ -287,8 +302,13 @@ public void readFromNBT(NBTTagCompound tag){
this.state = tag.getByte("state");
this.openTicks = tag.getInteger("openTicks");
this.animStartTime = tag.getInteger("animStartTime");
this.redstoned = tag.getBoolean("redstoned");
this.redstonePower = tag.getInteger("redstoned");
this.shouldUseBB = tag.getBoolean("shouldUseBB");
NBTTagCompound activatedBlocks = tag.getCompoundTag("activatedBlocks");
this.activatedBlocks.clear();
for(int i = 0; i < activatedBlocks.getKeySet().size()/3; i ++){
this.activatedBlocks.add(new BlockPos(activatedBlocks.getInteger("x"+i), activatedBlocks.getInteger("y"+i), activatedBlocks.getInteger("z"+i)));
}
super.readFromNBT(tag);
}

Expand All @@ -297,8 +317,17 @@ public NBTTagCompound writeToNBT(NBTTagCompound tag){
tag.setByte("state", state);
tag.setInteger("openTicks", openTicks);
tag.setLong("animStartTime", animStartTime);
tag.setBoolean("redstoned", redstoned);
tag.setInteger("redstoned", redstonePower);
tag.setBoolean("shouldUseBB", shouldUseBB);
NBTTagCompound activatedBlocks = new NBTTagCompound();
int i = 0;
for(BlockPos p : this.activatedBlocks){
activatedBlocks.setInteger("x"+i, p.getX());
activatedBlocks.setInteger("y"+i, p.getY());
activatedBlocks.setInteger("z"+i, p.getZ());
i++;
}
tag.setTag("activatedBlocks", activatedBlocks);
return super.writeToNBT(tag);
}

Expand Down Expand Up @@ -353,4 +382,23 @@ public World getControlWorld(){
return getWorld();
}

public void updateRedstonePower(BlockPos pos){
//Drillgon200: Best I could come up with without having to use dummy tile entities
boolean powered = world.isBlockIndirectlyGettingPowered(pos) > 0;
boolean contained = activatedBlocks.contains(pos);
if(!contained && powered){
activatedBlocks.add(pos);
if(redstonePower == -1){
redstonePower = 0;
}
redstonePower++;
} else if(contained && !powered){
activatedBlocks.remove(pos);
redstonePower--;
if(redstonePower == 0){
redstonePower = -1;
}
}
}

}

0 comments on commit 6ee3cfa

Please sign in to comment.