Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Fix reactor, Destroy Button and 3.0
Browse files Browse the repository at this point in the history
Allow GT Awakened to be used in draconic reactor
Change version from 1.* to 3.*, as was incompatible with some mods
Add a destruct button to the energy core
  • Loading branch information
IntegerLimit committed Mar 7, 2023
1 parent f5e22b4 commit 6cb432c
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mc_version=1.12.2
mod_version=1.1
mod_version=3.0
forge_version=14.23.5.2811
mappings=snapshot_20171003
bcore_version=2.4.19.+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,42 @@
import com.brandon3055.draconicevolution.GuiHandler;
import com.brandon3055.draconicevolution.api.IExtendedRFStorage;
import com.brandon3055.draconicevolution.lib.EnergyCoreBuilder;
import com.brandon3055.draconicevolution.utils.BlockStateMultiblockStorage;
import com.brandon3055.draconicevolution.utils.LogHelper;
import com.brandon3055.draconicevolution.world.EnergyCoreStructure;
import mezz.jei.util.Log;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.internal.FMLNetworkHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static net.minecraft.block.Block.spawnAsEntity;
import static net.minecraft.util.text.TextFormatting.RED;

/**
Expand Down Expand Up @@ -185,6 +200,47 @@ private long getCapacity() {
return (long) DEConfig.coreCapacity[tier.value - 1];
}

public void destroyCore(EntityPlayer player){
BlockStateMultiblockStorage storage = coreStructure.getStorageForTier(tier.value);
BlockPos start = getPos().add(coreStructure.getCoreOffset(tier.value));
Map<BlockPos, IBlockState> toRemove = new HashMap<>();
storage.forEachBlockState(start, toRemove::put);
World world = getWorld();
for (BlockPos blockPos: toRemove.keySet()) {
IBlockState state = toRemove.get(blockPos);
if (state != null && !state.equals(Blocks.AIR.getDefaultState()) &&
!state.equals(Block.REGISTRY.getObject(
new ResourceLocation("draconicevolution:energy_storage_core"))
.getDefaultState())){

if (!player.capabilities.isCreativeMode){
ItemStack stack = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
if (!insertItem(stack, player)){
spawnAsEntity(world, blockPos, stack);
}
}

world.setBlockState(blockPos, Blocks.AIR.getDefaultState());
SoundType soundtype = state.getBlock().getSoundType(state, world, pos, player);
world.playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundtype.getBreakSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
}
}
}

private boolean insertItem(ItemStack toInsert, EntityPlayer player){
IItemHandler handler = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (handler == null) return false;
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack inSlot = handler.getStackInSlot(i);
if (inSlot.isEmpty() || (inSlot.getItem().equals(toInsert.getItem()) && inSlot.getMetadata() == toInsert.getMetadata() && inSlot.getCount() < toInsert.getMaxStackSize())) {
ItemStack inserted = handler.insertItem(i, toInsert, false);
if (inserted.isEmpty() || inserted.getItem().equals(Items.AIR))
return true;
}
}
return false;
}

@Override
public void receivePacketFromClient(MCDataInput data, EntityPlayerMP client, int id) {
if (id == 0) { //Activate
Expand All @@ -198,12 +254,14 @@ public void receivePacketFromClient(MCDataInput data, EntityPlayerMP client, int
else if (id == 1) { //Tier Up
if (!active.value && tier.value < 8) {
tier.value++;
buildGuide.value = false;
validateStructure();
}
}
else if (id == 2) { //Tier Down
if (!active.value && tier.value > 1) {
tier.value--;
buildGuide.value = false;
validateStructure();
}
}
Expand All @@ -213,10 +271,17 @@ else if (id == 3) { //Toggle Guide
}
}
else if (id == 4) { //Build
if (!active.value) {
if (!active.value && !coreValid.value) {
startBuilder(client);
}
}

else if (id == 7) { //Destroy
if (coreValid.value && !active.value){
destroyCore(client);

}
}
}

private void startBuilder(EntityPlayer player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class GuiEnergyCore extends GuiContainer {
private GuiButton tierDown;
private GuiButton toggleGuide;
private GuiButton assembleCore;
private GuiButton destroyCore;
private GuiButton layerPlus;
private GuiButton layerMinus;
public static int layer = -1;
Expand Down Expand Up @@ -67,6 +68,9 @@ public void initGui() {

buttonList.add(layerMinus = new GuiButtonAHeight(5, guiLeft + 5, guiTop - 13, 70, 12, "Layer-"));
buttonList.add(layerPlus = new GuiButtonAHeight(6, guiLeft + 105, guiTop - 13, 70, 12, "Layer+"));

buttonList.add(destroyCore = new GuiButtonAHeight(7, guiLeft + 9, guiTop + 73 + 10, 162, 12, I18n.format("button.de.destroyCore.txt")));

layerPlus.visible = tile.buildGuide.value;
layerMinus.visible = tile.buildGuide.value;

Expand Down Expand Up @@ -209,17 +213,19 @@ private void updateButtonStates() {
tierDown.enabled = tile.tier.value > 1;
}

tierUp.visible = tierDown.visible = toggleGuide.visible = !tile.active.value;
tierUp.visible = tierDown.visible = !tile.active.value;
toggleGuide.visible = !tile.active.value && !tile.coreValid.value;
assembleCore.visible = !tile.coreValid.value;
activate.visible = tile.coreValid.value;
destroyCore.visible = tile.coreValid.value && !tile.active.value;

layerPlus.visible = tile.buildGuide.value;
layerMinus.visible = tile.buildGuide.value;
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
if (button.id < 5) {
if (button.id < 5 || button.id > 6) {
tile.sendPacketToServer(output -> {
}, button.id);
} else {
Expand All @@ -230,6 +236,7 @@ protected void actionPerformed(GuiButton button) throws IOException {
}
layer = MathHelper.clip(layer, -1, 6);
}
updateButtonStates();
}

public static void drawEnergyBar(Gui gui, int posX, int posY, int size, boolean horizontal, long energy, long maxEnergy, boolean toolTip, int mouseX, int mouseY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
import com.brandon3055.brandonscore.inventory.ContainerBCBase;
import com.brandon3055.draconicevolution.DEFeatures;
import com.brandon3055.draconicevolution.blocks.reactor.tileentity.TileReactorCore;
import com.brandon3055.draconicevolution.world.EnergyCoreStructure;
import gregtech.api.GregTechAPI;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.Materials;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.common.blocks.MetaBlocks;
import gregtech.common.items.MetaItem1;
import gregtech.common.items.MetaItems;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
Expand Down Expand Up @@ -116,6 +126,16 @@ else if (slotId <= 35) {
return ItemStack.EMPTY;
}

// Returns list with [0] = block, [1] = ingot, [2] = nugget
public static ItemStack[] getGTDraconium(){
Material gtDraconiumMaterial = GregTechAPI.MaterialRegistry.get("awakened_draconium");
IBlockState gtDraconiumState = MetaBlocks.COMPRESSED.get(gtDraconiumMaterial).getBlock(gtDraconiumMaterial);
ItemStack gtDraconiumBlock = new ItemStack(gtDraconiumState.getBlock(), 1, gtDraconiumState.getBlock().getMetaFromState(gtDraconiumState));
ItemStack gtDraconiumIngot = OreDictUnifier.get(OrePrefix.ingot, gtDraconiumMaterial, 1);
ItemStack gtDraconiumNugget = OreDictUnifier.get(OrePrefix.nugget, gtDraconiumMaterial, 1);
return new ItemStack[]{gtDraconiumBlock, gtDraconiumIngot, gtDraconiumNugget};
}

private int getFuelValue(ItemStack stack) {
if (stack.isEmpty()) {
return 0;
Expand All @@ -129,6 +149,18 @@ else if (stack.getItem() == DEFeatures.draconicIngot) {
else if (stack.getItem() == DEFeatures.nugget && stack.getItemDamage() == 1) {
return stack.getCount() * 16;
}
else if (GregTechAPI.MaterialRegistry.get("awakened_draconium") != null){
}
ItemStack[] gtDraconium = getGTDraconium();
if (stack.getItem().equals(gtDraconium[0].getItem()) && stack.getMetadata() == gtDraconium[0].getMetadata()) {
return stack.getCount() * 1296;
}
else if (stack.getItem().equals(gtDraconium[1].getItem()) && stack.getMetadata() == gtDraconium[1].getMetadata()) {
return stack.getCount() * 144;
}
else if (stack.getItem().equals(gtDraconium[2].getItem()) && stack.getMetadata() == gtDraconium[2].getMetadata()) {
return stack.getCount() * 16;
}
return 0;
}

Expand Down Expand Up @@ -185,14 +217,28 @@ public ItemStack getStack() {
int ingot = (fuel % 1296) / 144;
int nugget = ((fuel % 1296) % 144) / 16;

if (index == 0 && block > 0) {
return new ItemStack(DEFeatures.draconicBlock, block);
}
else if (index == 1 && ingot > 0) {
return new ItemStack(DEFeatures.draconicIngot, ingot);
if (GregTechAPI.MaterialRegistry.get("awakened_draconium") != null) {
ItemStack[] gtDraconium = ContainerReactor.getGTDraconium();
if (index == 0 && block > 0) {
return new ItemStack(gtDraconium[0].getItem(), block, gtDraconium[0].getMetadata());
}
else if (index == 1 && ingot > 0) {
return new ItemStack(gtDraconium[1].getItem(), ingot, gtDraconium[1].getMetadata());
}
else if (index == 2 && nugget > 0) {
return new ItemStack(gtDraconium[2].getItem(), nugget, gtDraconium[2].getMetadata());
}
}
else if (index == 2 && nugget > 0) {
return new ItemStack(DEFeatures.nugget, nugget, 1);
else{
if (index == 0 && block > 0) {
return new ItemStack(DEFeatures.draconicBlock, block);
}
else if (index == 1 && ingot > 0) {
return new ItemStack(DEFeatures.draconicIngot, ingot);
}
else if (index == 2 && nugget > 0) {
return new ItemStack(DEFeatures.nugget, nugget, 1);
}
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private boolean extractItem(ItemStack toExtract) {
ItemStack inSlot = handler.getStackInSlot(i);
if (!inSlot.isEmpty() && inSlot.getItem().equals(toExtract.getItem()) && inSlot.getMetadata() == toExtract.getMetadata()) {
ItemStack extracted = handler.extractItem(i, 1, false);
if (!extracted.isEmpty() && extracted.getItem().equals(toExtract.getItem())) {
if (!extracted.isEmpty() && extracted.getItem().equals(toExtract.getItem()) && extracted.getMetadata() == toExtract.getMetadata()) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* Created by brandon3055 on 1/4/2016.
*/
public class EnergyCoreStructure extends BlockStateMultiblockHelper {
private final int FLAG_RENDER = 0;
private final int FLAG_RENDER = 0;
private final int FLAG_FORME = 1;
private final int FLAG_REVERT = 2;
private BlockStateMultiblockStorage[] structureTiers = new BlockStateMultiblockStorage[8];
Expand Down Expand Up @@ -324,8 +324,6 @@ private void renderBuildGuide(IBlockState state, World world, BlockPos pos, Bloc
// Special case for GT Blocks
Block block = state.getBlock();

ItemStack itemstack = new ItemStack(block, 1, block.getMetaFromState(state));

if (block instanceof BlockCompressed) {
BlockCompressed compressed = (BlockCompressed) block;
Material material = state.getValue(compressed.variantProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ ecore.de.already_assembling.txt=Assembly already in progress!
ecore.de.assemble_found_invalid.txt=Error: Found invalid block [%s at %s] within build area!
ecore.de.assemble_error_expected_air.txt=An error occurred while building structure! Expected air block at %s.
ecore.de.assemble_missing_required.txt=Unable to complete structure! Missing required block(s) %s.
button.de.destroyCore.txt=Destroy Core

//---- Reactor ----//
gui.reactor.draconicReactor.txt=Draconic Reactor
Expand Down

0 comments on commit 6cb432c

Please sign in to comment.