Code cleanup (#39)

* Updated build script and dependencies

* Optimized Energy Pylon

* Changed names of few variables

* Started optimizing Energy Storage Core

* Optimized Invisible Multiblock

* Fixed Energy Pylon state update logic

* Round 2 of Energy Storage Core optimization

* Finished optimization of Energy Storage Core

* Cleared method from duplicate code

* Cleaned up Particle Generator code

* Optimized Dislocator Receptacle

* Cleaned up Portal code

* Cleaned up code of PortalHelper

* Changed Reactor Part interface

* Optimized Reactor Energy Injector

* Optimized Reactor Stabilizer

* Stage 1 of Reactor Core refactoring

* Cleaned up Reactor Container code

Fixed bug that allowed to dupe awakened draconium and chaos shards

* Cleaned up Reactor GUI code

* Removed unnecessary checks in GUI Handler

* Removed unnecessary revalidation of reactor structure

* Migrate Reactor Energy Injector to Forge Direction

* Migrate Reactor Stabilizer to Forge Direction

* Introduced Comparator Mode enumeration

* Migrated Reactor Energy Injector and Stabilizer to use ComparatorMode

* Migrated Reactor Core to use ReactorState enumeration

* Clean up Particle Reactor Beam

* Remove stale todo lists

* Renamed several member for clarity

* Cleaned code of Energy Pylon render

* Cleaned up code of Player Detector

* Cleaned up code of Advanced Player Detector

* Cleaned up GUI and Container of Advanced Player Detector

* Removed unnecessary block update

* Removed unnecessary block updates from Creative Keystone and other blocks

* Changed naming style of fields of Particle Generator to camel case

* Cleaned up code of Particle Generator GUI

* Updated build script

* Implemented missing interface for Tile Entity providers

* Fixed range of property of Particle Generator

* Addressed pull request issues

* Added missing localization items for Particle Generator

* And this one too

* Updated switch statements to use new syntax
This commit is contained in:
Alexander Anishin authored and GitHub committed 2023-06-15 19:09:42 +02:00
1 parent 276b17fc9d
commit adf73c81f4
53 files changed
+3863 -5490

No files matched your search

+25 -8
View File
@@ -1,4 +1,4 @@
//version: 1683373797
//version: 1685785062
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
@@ -69,7 +69,7 @@ plugins {
id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version
id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.7'
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.14'
}
print("You might want to check out './gradlew :faq' if your build fails.\n")
@@ -569,9 +569,10 @@ repositories {
def mixinProviderGroup = "io.github.legacymoddingmc"
def mixinProviderModule = "unimixins"
def mixinProviderVersion = "0.1.6"
def mixinProviderVersion = "0.1.7.1"
def mixinProviderSpecNoClassifer = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"
def mixinProviderSpec = "${mixinProviderSpecNoClassifer}:dev"
ext.mixinProviderSpec = mixinProviderSpec
dependencies {
if (usesMixins.toBoolean()) {
@@ -729,7 +730,7 @@ dependencies {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
}
if (modId != 'hodgepodge') {
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.8')
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.13')
}
java17PatchDependencies('net.minecraft:launchwrapper:1.15') {transitive = false}
@@ -822,6 +823,18 @@ public abstract class RunHotswappableMinecraftTask extends RunMinecraftTask {
}
this.classpath(project.java17DependenciesCfg)
}
public void setup(Project project) {
super.setup(project)
if (project.usesMixins.toBoolean()) {
this.extraJvmArgs.addAll(project.provider(() -> {
def mixinCfg = project.configurations.detachedConfiguration(project.dependencies.create(project.mixinProviderSpec))
mixinCfg.canBeConsumed = false
mixinCfg.transitive = false
enableHotswap ? ["-javaagent:" + mixinCfg.singleFile.absolutePath] : []
}))
}
}
}
def runClient17Task = tasks.register("runClient17", RunHotswappableMinecraftTask, Distribution.CLIENT, "runClient")
@@ -1263,10 +1276,14 @@ tasks.register('faq') {
description = 'Prints frequently asked questions about building a project'
doLast {
print("If your build fails to fetch dependencies, they might have been deleted and replaced by newer " +
"versions.\nCheck if the versions you try to fetch are still on the distributing sites.\n" +
"The links can be found in repositories.gradle and build.gradle:repositories, " +
"not build.gradle:buildscript.repositories - this one is for gradle plugin metadata.")
print("If your build fails to fetch dependencies, run './gradlew updateDependencies'. " +
"Or you can manually check if the versions are still on the distributing sites - " +
"the links can be found in repositories.gradle and build.gradle:repositories, " +
"but not build.gradle:buildscript.repositories - those ones are for gradle plugin metadata.\n\n" +
"If your build fails to recognize the syntax of new Java versions, enable Jabel in your " +
"gradle.properties. See how it's done in GTNH ExampleMod/gradle.properties. " +
"However, keep in mind that Jabel enables only syntax features, but not APIs that were introduced in " +
"Java 9 or later.")
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ dependencies {
compileOnly("com.github.GTNewHorizons:OpenComputers:1.9.5-GTNH:api") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.3.50-GTNH:dev") {
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.3.53-GTNH:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:CodeChickenLib:1.1.8:dev") {
+2
View File
@@ -21,6 +21,8 @@ forgeVersion = 10.13.4.1614
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
developmentEnvironmentUserName = Developer
enableModernJavaSyntax = true
# Define a source file of your project with:
# public static final String VERSION = "GRADLETOKEN_VERSION";
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
@@ -333,7 +333,7 @@ public class ClientProxy extends CommonProxy {
beam.setDead();
return null;
} else {
beam.update(render);
beam.update();
}
return beam;
}
@@ -12,52 +12,44 @@ import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.rea
*/
public class ReactorSound extends PositionedSound implements ITickableSound {
private static ResourceLocation sound = new ResourceLocation(References.RESOURCESPREFIX + "coreSound");
public boolean donePlaying = false;
private TileReactorCore tile;
private static final ResourceLocation sound = new ResourceLocation(References.RESOURCESPREFIX + "coreSound");
public boolean isDonePlaying = false;
private final TileReactorCore core;
public ReactorSound(TileReactorCore tile) {
public ReactorSound(TileReactorCore core) {
super(sound);
this.tile = tile;
this.xPosF = (float) tile.xCoord + 0.5F;
this.yPosF = (float) tile.yCoord + 0.5F;
this.zPosF = (float) tile.zCoord + 0.5F;
this.core = core;
this.xPosF = (float) core.xCoord + 0.5F;
this.yPosF = (float) core.yCoord + 0.5F;
this.zPosF = (float) core.zCoord + 0.5F;
this.repeat = true;
this.volume = 1.5F;
}
@Override
public boolean isDonePlaying() {
return donePlaying;
return isDonePlaying;
}
@Override
public void update() {
volume = (tile.renderSpeed - 0.5F) * 2F;
if (tile.reactionTemperature > 8000) {
volume += (float) ((tile.reactionTemperature - 8000D) / 1000D);
volume = (core.renderSpeed - 0.5F) * 2F;
if (core.reactionTemperature > 8000) {
volume += (float) ((core.reactionTemperature - 8000D) / 1000D);
}
if (tile.reactionTemperature > 2000 && tile.maxFieldCharge > 0
&& tile.fieldCharge < (tile.maxFieldCharge * 0.2D)) {
volume += 2D - ((tile.fieldCharge / tile.maxFieldCharge) * 10D);
if (core.reactionTemperature > 2000 && core.maxFieldCharge > 0
&& core.fieldCharge < (core.maxFieldCharge * 0.2D)) {
volume += 2D - ((core.fieldCharge / core.maxFieldCharge) * 10D);
}
if (tile.reactionTemperature > 2000 && tile.reactorFuel + tile.convertedFuel > 0
&& tile.reactorFuel < (double) (tile.reactorFuel + tile.convertedFuel) * 0.2D) {
volume += 2D - ((tile.reactorFuel / (tile.reactorFuel + tile.convertedFuel)) * 10D);
if (core.reactionTemperature > 2000 && core.reactorFuel + core.convertedFuel > 0
&& core.reactorFuel < (double) (core.reactorFuel + core.convertedFuel) * 0.2D) {
volume += 2D - ((float) core.reactorFuel / (core.reactorFuel + core.convertedFuel)) * 10D;
}
field_147663_c = 0.5F + volume / 2F;
if (tile.isInvalid() || !tile.getWorldObj().getChunkFromBlockCoords(tile.xCoord, tile.zCoord).isChunkLoaded) { // ||
// player
// ==
// null
// ||
// tile.getDistanceFrom(player.posX,
// player.posY,
// player.posZ) > 512){
donePlaying = true;
if (core.isInvalid() || !core.getWorldObj().getChunkFromBlockCoords(core.xCoord, core.zCoord).isChunkLoaded) {
isDonePlaying = true;
repeat = false;
}
}
File diff suppressed because it is too large. Load diff
@@ -1,12 +1,12 @@
package com.brandon3055.draconicevolution.client.gui;
import java.util.ArrayList;
import java.util.Arrays;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
@@ -25,78 +25,76 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GUIPlayerDetector extends GuiContainer {
public EntityPlayer player;
private TilePlayerDetectorAdvanced detector;
public boolean showInvSlots = true;
private boolean editMode = false;
private int range = 0;
private int maxRange = 20;
private boolean whitelist = false;
private boolean initScedualed = false;
private int initTick = 0;
private String[] names = new String[42];
private GuiTextField selectedNameText;
private int selected = -1;
private boolean outputInverted = false;
public GUIPlayerDetector(InventoryPlayer invPlayer, TilePlayerDetectorAdvanced detector) {
super(detector.getGuiContainer(invPlayer));
this.inventorySlots = new ContainerPlayerDetector(invPlayer, detector, this);
for (int i = 0; i < names.length; i++) names[i] = "";
xSize = 176;
ySize = 198;
this.detector = detector;
this.player = invPlayer.player;
syncWithServer();
}
private static final ResourceLocation texture = new ResourceLocation(
References.MODID.toLowerCase(),
"textures/gui/PlayerDetector.png");
private final ContainerPlayerDetector container;
private boolean isInEditMode = false;
private int range = 0;
private boolean isInWhitelistMode = false;
private boolean isOutputInverted = false;
private boolean isInitScheduled = false;
private int initTick = 0;
private final String[] names = new String[42];
private GuiTextField selectedNameText;
private int selectedMameIndex = -1;
public GUIPlayerDetector(InventoryPlayer playerInventory, TilePlayerDetectorAdvanced detector) {
super(detector.getGuiContainer(playerInventory));
container = (ContainerPlayerDetector) inventorySlots;
Arrays.fill(names, "");
xSize = 176;
ySize = 198;
syncWithServer();
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
GL11.glColor4f(1, 1, 1, 1);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
if (editMode) {
if (isInEditMode) {
drawTexturedModalRect(guiLeft + 3, guiTop + ySize / 2, 3, 3, xSize - 6, (ySize / 2) - 3);
drawNameChart(x, y);
}
if (showInvSlots) drawTexturedModalRect(guiLeft + 142, guiTop + 19, xSize, 0, 23, 41);
if (container.shouldShowInventory()) {
drawTexturedModalRect(guiLeft + 142, guiTop + 19, xSize, 0, 23, 41);
}
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y) {
drawGuiText(x, y);
drawGuiText();
}
@Override
public void drawScreen(int x, int y, float p_73863_3_) {
super.drawScreen(x, y, p_73863_3_);
ArrayList<String> lines = new ArrayList<String>();
public void drawScreen(int x, int y, float partialTicks) {
super.drawScreen(x, y, partialTicks);
ArrayList<String> lines = new ArrayList<>();
lines.add("Camouflage");
if ((x - guiLeft > 142 && x - guiLeft < 160) && (y - guiTop > 19 && y - guiTop < 37) && showInvSlots)
if ((x - guiLeft > 142 && x - guiLeft < 160) && (y - guiTop > 19 && y - guiTop < 37)
&& container.shouldShowInventory()) {
drawHoveringText(lines, x, y, fontRendererObj);
}
}
@Override
@SuppressWarnings("unchecked")
public void initGui() {
super.initGui();
buttonList.clear();
if (!editMode) {
String wt = whitelist ? "White List" : "Black List";
int centre = width / 2;
buttonList.add(new GuiButton(0, centre - 20 - 20, guiTop + 20, 20, 20, "+"));
buttonList.add(new GuiButton(1, centre + 20, guiTop + 20, 20, 20, "-"));
buttonList.add(new GuiButton(3, centre - 40, guiTop + 45, 60, 20, wt));
buttonList.add(new GuiButton(4, centre + 20, guiTop + 45, 20, 20, "!"));
buttonList.add(new GuiButton(6, centre - 40, guiTop + 70, 80, 20, "Invert Output"));
if (!isInEditMode) {
String mode = isInWhitelistMode ? "White List" : "Black List";
int center = width / 2;
buttonList.add(new GuiButton(0, center - 20 - 20, guiTop + 20, 20, 20, "+"));
buttonList.add(new GuiButton(1, center + 20, guiTop + 20, 20, 20, "-"));
buttonList.add(new GuiButton(3, center - 40, guiTop + 45, 60, 20, mode));
buttonList.add(new GuiButton(4, center + 20, guiTop + 45, 20, 20, "!"));
buttonList.add(new GuiButton(6, center - 40, guiTop + 70, 80, 20, "Invert Output"));
} else {
buttonList.add(new GuiButton(5, guiLeft - 40, guiTop + ySize - 20, 40, 20, "Back"));
}
@@ -106,112 +104,108 @@ public class GUIPlayerDetector extends GuiContainer {
selectedNameText.setDisabledTextColour(-1);
selectedNameText.setEnableBackgroundDrawing(true);
selectedNameText.setMaxStringLength(40);
selectedNameText.setVisible(editMode);
// ID
// buttonList.add(new GuiButton(0, guiLeft + 85, guiTop , 85, 20, "sgASGgs"));
// syncWithServer();
selectedNameText.setVisible(isInEditMode);
}
@Override
protected void actionPerformed(GuiButton button) {
switch (button.id) {
case 0: // Range +
range = (range < maxRange) ? range + 1 : maxRange;
case 0 -> { // Range +
range = Math.min(range + 1, TilePlayerDetectorAdvanced.MAXIMUM_RANGE);
DraconicEvolution.network.sendToServer(new PlayerDetectorButtonPacket((byte) 0, (byte) range));
break;
case 1: // Range -
range = (range > 1) ? range - 1 : 1;
}
case 1 -> { // Range -
range = Math.max(range - 1, TilePlayerDetectorAdvanced.MINIMUM_RANGE);
DraconicEvolution.network.sendToServer(new PlayerDetectorButtonPacket((byte) 0, (byte) range));
break;
case 3: // White List -
initScedualed = true;
editMode = true;
showInvSlots = false;
((ContainerPlayerDetector) this.inventorySlots).updateContainerSlots();
break;
case 4: // Toggle White List -
whitelist = !whitelist;
initScedualed = true;
byte val = (byte) (whitelist ? 1 : 0);
DraconicEvolution.network.sendToServer(new PlayerDetectorButtonPacket((byte) 1, val));
break;
case 5: // Back -
editMode = false;
showInvSlots = true;
((ContainerPlayerDetector) this.inventorySlots).updateContainerSlots();
initScedualed = true;
break;
case 6: // Back -
outputInverted = !outputInverted;
initScedualed = true;
byte val2 = (byte) (outputInverted ? 1 : 0);
DraconicEvolution.network.sendToServer(new PlayerDetectorButtonPacket((byte) 2, val2));
break;
}
case 3 -> { // Edit Whitelist/Blacklist
isInitScheduled = true;
isInEditMode = true;
container.setShouldShowInventory(false);
}
case 4 -> { // Toggle Whitelist/Blacklist mode
isInitScheduled = true;
isInWhitelistMode = !isInWhitelistMode;
byte whitelistMode = (byte) (isInWhitelistMode ? 1 : 0);
DraconicEvolution.network.sendToServer(new PlayerDetectorButtonPacket((byte) 1, whitelistMode));
}
case 5 -> { // Back
isInitScheduled = true;
isInEditMode = false;
container.setShouldShowInventory(true);
}
case 6 -> { // Invert Output
isInitScheduled = true;
isOutputInverted = !isOutputInverted;
byte outputMode = (byte) (isOutputInverted ? 1 : 0);
DraconicEvolution.network.sendToServer(new PlayerDetectorButtonPacket((byte) 2, outputMode));
}
}
// DraconicEvolution.channelHandler.sendToServer(new ButtonPacket((byte) 0, true));
}
@Override
protected void keyTyped(char par1, int par2) {
if (this.selectedNameText.textboxKeyTyped(par1, par2)) return;
else if (par2 == 28) {
protected void keyTyped(char typedChar, int keyCode) {
if (this.selectedNameText.textboxKeyTyped(typedChar, keyCode)) {
return;
}
if (keyCode == 28) {
if (selectedNameText.isFocused()) {
names[selected] = selectedNameText.getText();
names[selectedMameIndex] = selectedNameText.getText();
selectedNameText.setText("");
selectedNameText.setFocused(false);
DraconicEvolution.network
.sendToServer(new PlayerDetectorStringPacket((byte) selected, names[selected]));
selected = -1;
DraconicEvolution.network.sendToServer(
new PlayerDetectorStringPacket((byte) selectedMameIndex, names[selectedMameIndex]));
selectedMameIndex = -1;
}
} else super.keyTyped(par1, par2);
} else {
super.keyTyped(typedChar, keyCode);
}
}
@Override
public void updateScreen() {
if (initScedualed) initTick++;
if (isInitScheduled) {
initTick++;
}
if (initTick > 1) {
initTick = 0;
initScedualed = false;
isInitScheduled = false;
initGui();
}
super.updateScreen();
}
@Override
protected void mouseClicked(int x, int y, int par3) {
super.mouseClicked(x, y, par3);
if (editMode) selectName(x - guiLeft, y - guiTop);
// this.selectedNameText.mouseClicked(x - guiLeft, y - guiTop, par3);
protected void mouseClicked(int x, int y, int mouseButton) {
super.mouseClicked(x, y, mouseButton);
if (isInEditMode) {
selectName(x - guiLeft, y - guiTop);
}
}
private void drawGuiText(int rawX, int rawY) {
if (!editMode) {
drawCenteredString(fontRendererObj, "Advanced Player Detector", xSize / 2, 5, 0x00FFFF);
fontRendererObj.drawString("Range:", 73, 21, 0x000000, false);
fontRendererObj.drawString("Output Inverted: " + String.valueOf(outputInverted), 33, 97, 0x000000, false);
if (range < 10) fontRendererObj.drawString("" + range, 85, 31, 0x000000, false);
else fontRendererObj.drawString("" + range, 82, 31, 0x000000, false);
} else {
if (selected != -1) drawCenteredString(fontRendererObj, "Press Enter to save", xSize / 2, -22, 0xFF0000);
for (int i = 0; i < 21; i++) {
for (int j = 0; j < 2; j++) {
if (i + j * 21 != selected) {
String s = names[i + j * 21];
if (s.length() > 13) s = s.substring(0, 13) + "...";
fontRendererObj.drawString(s, 5 + j * 84, 6 + i * 9, 0x980000);
private void drawGuiText() {
if (isInEditMode) {
if (selectedMameIndex != -1) {
drawCenteredString(fontRendererObj, "Press Enter to save", xSize / 2, -22, 0xFF0000);
}
for (int row = 0; row < 21; row++) {
for (int column = 0; column < 2; column++) {
if (row + column * 21 != selectedMameIndex) {
String name = names[row + column * 21];
if (name.length() > 13) {
name = name.substring(0, 13) + "...";
}
fontRendererObj.drawString(name, 5 + column * 84, 6 + row * 9, 0x980000);
}
}
}
}
} else {
drawCenteredString(fontRendererObj, "Advanced Player Detector", xSize / 2, 5, 0x00FFFF);
fontRendererObj.drawString("Range:", 73, 21, 0x000000, false);
fontRendererObj.drawString("Output Inverted: " + isOutputInverted, 33, 97, 0x000000, false);
fontRendererObj.drawString(String.valueOf(range), range < 10 ? 85 : 82, 31, 0x000000, false);
}
selectedNameText.drawTextBox();
}
@@ -219,39 +213,46 @@ public class GUIPlayerDetector extends GuiContainer {
int x = rawX - guiLeft;
int y = rawY - guiTop;
for (int i = 0; i < 21; i++) {
drawTexturedModalRect(guiLeft + 4, guiTop + 4 + i * 9, 0, ySize, 186, 10);
for (int row = 0; row < 21; row++) {
drawTexturedModalRect(guiLeft + 4, guiTop + 4 + row * 9, 0, ySize, 186, 10);
}
for (int i = 0; i < 21; i++) {
for (int j = 0; j < 2; j++) {
if ((x > 4 + j * 84 && x < (xSize / 2) - 1 + j * 82) && (y > 4 + i * 9 && y < 13 + i * 9)
|| i + j * 21 == selected)
drawTexturedModalRect(guiLeft + 5 + j * 84, guiTop + 5 + i * 9, 0, ySize + 10, 82, 8);
for (int row = 0; row < 21; row++) {
for (int column = 0; column < 2; column++) {
if ((x > 4 + column * 84 && x < (xSize / 2) - 1 + column * 82) && (y > 4 + row * 9 && y < 13 + row * 9)
|| row + column * 21 == selectedMameIndex)
drawTexturedModalRect(guiLeft + 5 + column * 84, guiTop + 5 + row * 9, 0, ySize + 10, 82, 8);
}
}
}
public void selectName(int x, int y) {
if (initScedualed) return;
if (isInitScheduled) {
return;
}
for (int i = 0; i < 21; i++) {
for (int j = 0; j < 2; j++) {
if ((x > 4 + j * 84 && x < (xSize / 2) - 1 + j * 82) && (y > 4 + i * 9 && y < 13 + i * 9)) {
selected = i + j * 21;
selectedNameText.setText(names[i + j * 21]);
for (int row = 0; row < 21; row++) {
for (int column = 0; column < 2; column++) {
if ((x > 4 + column * 84 && x < (xSize / 2) - 1 + column * 82)
&& (y > 4 + row * 9 && y < 13 + row * 9)) {
selectedMameIndex = row + column * 21;
selectedNameText.setText(names[row + column * 21]);
selectedNameText.setFocused(true);
return;
}
}
}
}
private void syncWithServer() {
this.whitelist = detector.whiteList;
TilePlayerDetectorAdvanced detector = container.getDetector();
isInWhitelistMode = detector.isInWhiteListMode;
for (int i = 0; i < detector.names.length; i++) {
if (detector.names[i] != null) names[i] = detector.names[i];
if (detector.names[i] != null) {
names[i] = detector.names[i];
}
}
range = detector.range;
outputInverted = detector.outputInverted;
isOutputInverted = detector.isOutputInverted;
}
}
@@ -8,9 +8,28 @@ import com.brandon3055.draconicevolution.DraconicEvolution;
import com.brandon3055.draconicevolution.client.gui.componentguis.GUIManual;
import com.brandon3055.draconicevolution.client.gui.componentguis.GUIReactor;
import com.brandon3055.draconicevolution.client.gui.componentguis.GUIToolConfig;
import com.brandon3055.draconicevolution.common.container.*;
import com.brandon3055.draconicevolution.common.container.ContainerAdvTool;
import com.brandon3055.draconicevolution.common.container.ContainerDissEnchanter;
import com.brandon3055.draconicevolution.common.container.ContainerDraconiumChest;
import com.brandon3055.draconicevolution.common.container.ContainerEnergyInfuser;
import com.brandon3055.draconicevolution.common.container.ContainerGenerator;
import com.brandon3055.draconicevolution.common.container.ContainerGrinder;
import com.brandon3055.draconicevolution.common.container.ContainerPlayerDetector;
import com.brandon3055.draconicevolution.common.container.ContainerReactor;
import com.brandon3055.draconicevolution.common.container.ContainerSunDial;
import com.brandon3055.draconicevolution.common.container.ContainerUpgradeModifier;
import com.brandon3055.draconicevolution.common.container.ContainerWeatherController;
import com.brandon3055.draconicevolution.common.inventory.InventoryTool;
import com.brandon3055.draconicevolution.common.tileentities.*;
import com.brandon3055.draconicevolution.common.tileentities.TileDissEnchanter;
import com.brandon3055.draconicevolution.common.tileentities.TileDraconiumChest;
import com.brandon3055.draconicevolution.common.tileentities.TileEnergyInfuser;
import com.brandon3055.draconicevolution.common.tileentities.TileGenerator;
import com.brandon3055.draconicevolution.common.tileentities.TileGrinder;
import com.brandon3055.draconicevolution.common.tileentities.TileParticleGenerator;
import com.brandon3055.draconicevolution.common.tileentities.TilePlayerDetectorAdvanced;
import com.brandon3055.draconicevolution.common.tileentities.TileSunDial;
import com.brandon3055.draconicevolution.common.tileentities.TileUpgradeModifier;
import com.brandon3055.draconicevolution.common.tileentities.TileWeatherController;
import com.brandon3055.draconicevolution.common.tileentities.gates.TileGate;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore;
@@ -41,175 +60,145 @@ public class GuiHandler implements IGuiHandler {
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case GUIID_WEATHER_CONTROLLER:
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileWeatherController) {
return new ContainerWeatherController(player.inventory, (TileWeatherController) te);
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
switch (id) {
case GUIID_WEATHER_CONTROLLER -> {
if (tile instanceof TileWeatherController weatherController) {
return new ContainerWeatherController(player.inventory, weatherController);
}
break;
case GUIID_SUN_DIAL:
TileEntity te1 = world.getTileEntity(x, y, z);
if (te1 != null && te1 instanceof TileSunDial) {
return new ContainerSunDial(player.inventory, (TileSunDial) te1);
}
case GUIID_SUN_DIAL -> {
if (tile instanceof TileSunDial sunDial) {
return new ContainerSunDial(player.inventory, sunDial);
}
break;
case GUIID_GRINDER:
TileEntity te2 = world.getTileEntity(x, y, z);
if (te2 != null && te2 instanceof TileGrinder) {
return new ContainerGrinder(player.inventory, (TileGrinder) te2);
}
case GUIID_GRINDER -> {
if (tile instanceof TileGrinder grinder) {
return new ContainerGrinder(player.inventory, grinder);
}
break;
case GUIID_PLAYERDETECTOR:
TileEntity detector = world.getTileEntity(x, y, z);
if (detector != null && detector instanceof TilePlayerDetectorAdvanced) {
return new ContainerPlayerDetector(player.inventory, (TilePlayerDetectorAdvanced) detector);
}
case GUIID_PLAYERDETECTOR -> {
if (tile instanceof TilePlayerDetectorAdvanced detector) {
return new ContainerPlayerDetector(player.inventory, detector);
}
break;
case GUIID_ENERGY_INFUSER:
TileEntity infuser = world.getTileEntity(x, y, z);
if (infuser != null && infuser instanceof TileEnergyInfuser) {
return new ContainerEnergyInfuser(player.inventory, (TileEnergyInfuser) infuser);
}
case GUIID_ENERGY_INFUSER -> {
if (tile instanceof TileEnergyInfuser infuser) {
return new ContainerEnergyInfuser(player.inventory, infuser);
}
break;
case GUIID_GENERATOR:
TileEntity generator = world.getTileEntity(x, y, z);
if (generator != null && generator instanceof TileGenerator) {
return new ContainerGenerator(player.inventory, (TileGenerator) generator);
}
case GUIID_GENERATOR -> {
if (tile instanceof TileGenerator generator) {
return new ContainerGenerator(player.inventory, generator);
}
break;
case GUIID_DISSENCHANTER:
TileEntity dissenchanter = world.getTileEntity(x, y, z);
if (dissenchanter != null && dissenchanter instanceof TileDissEnchanter) {
return new ContainerDissEnchanter(player.inventory, (TileDissEnchanter) dissenchanter);
}
case GUIID_DISSENCHANTER -> {
if (tile instanceof TileDissEnchanter dissenchanter) {
return new ContainerDissEnchanter(player.inventory, dissenchanter);
}
break;
case GUIID_DRACONIC_CHEST:
TileEntity containerChest = world.getTileEntity(x, y, z);
if (containerChest != null && containerChest instanceof TileDraconiumChest) {
return new ContainerDraconiumChest(player.inventory, (TileDraconiumChest) containerChest);
}
case GUIID_DRACONIC_CHEST -> {
if (tile instanceof TileDraconiumChest draconiumChest) {
return new ContainerDraconiumChest(player.inventory, draconiumChest);
}
break;
case GUIID_REACTOR:
TileEntity reactor = world.getTileEntity(x, y, z);
if (reactor != null && reactor instanceof TileReactorCore) {
return new ContainerReactor(player, (TileReactorCore) reactor);
}
case GUIID_REACTOR -> {
if (tile instanceof TileReactorCore reactorCore) {
return new ContainerReactor(player, reactorCore);
}
break;
case GUIID_TOOL_CONFIG:
}
case GUIID_TOOL_CONFIG -> {
return new ContainerAdvTool(player.inventory, new InventoryTool(player, null));
case GUIID_UPGRADE_MODIFIER:
TileEntity containerTemp = world.getTileEntity(x, y, z);
if (containerTemp != null && containerTemp instanceof TileUpgradeModifier) {
return new ContainerUpgradeModifier(player.inventory, (TileUpgradeModifier) containerTemp);
}
case GUIID_UPGRADE_MODIFIER -> {
if (tile instanceof TileUpgradeModifier upgradeModifier) {
return new ContainerUpgradeModifier(player.inventory, upgradeModifier);
}
break;
// case GUIID_CONTAINER_TEMPLATE:
// TileEntity containerTemp = world.getTileEntity(x, y, z);
// if (containerTemp != null && containerTemp instanceof TileContainerTemplate) {
// return new ContainerTemplate(player.inventory, (TileContainerTemplate) containerTemp);
// }
// break;
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case GUIID_WEATHER_CONTROLLER:
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileWeatherController) {
return new GUIWeatherController(player.inventory, (TileWeatherController) te);
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
switch (id) {
case GUIID_WEATHER_CONTROLLER -> {
if (tile instanceof TileWeatherController weatherController) {
return new GUIWeatherController(player.inventory, weatherController);
}
break;
case GUIID_SUN_DIAL:
TileEntity te1 = world.getTileEntity(x, y, z);
if (te1 != null && te1 instanceof TileSunDial) {
return new GUISunDial(player.inventory, (TileSunDial) te1);
}
case GUIID_SUN_DIAL -> {
if (tile instanceof TileSunDial sunDial) {
return new GUISunDial(player.inventory, sunDial);
}
break;
case GUIID_TELEPORTER:
}
case GUIID_TELEPORTER -> {
return new GUITeleporter(player);
case GUIID_GRINDER:
TileEntity te2 = world.getTileEntity(x, y, z);
if (te2 != null && te2 instanceof TileGrinder) {
return new GUIGrinder(player.inventory, (TileGrinder) te2);
}
case GUIID_GRINDER -> {
if (tile instanceof TileGrinder grinder) {
return new GUIGrinder(player.inventory, grinder);
}
break;
case GUIID_PARTICLEGEN:
TileEntity gen = world.getTileEntity(x, y, z);
return (gen != null && gen instanceof TileParticleGenerator)
? new GUIParticleGenerator((TileParticleGenerator) gen, player)
: null;
case GUIID_PLAYERDETECTOR:
TileEntity detector = world.getTileEntity(x, y, z);
if (detector != null && detector instanceof TilePlayerDetectorAdvanced) {
return new GUIPlayerDetector(player.inventory, (TilePlayerDetectorAdvanced) detector);
}
case GUIID_PARTICLEGEN -> {
if (tile instanceof TileParticleGenerator particleGenerator) {
return new GUIParticleGenerator(particleGenerator);
}
break;
case GUIID_ENERGY_INFUSER:
TileEntity infuser = world.getTileEntity(x, y, z);
if (infuser != null && infuser instanceof TileEnergyInfuser) {
return new GUIEnergyInfuser(player.inventory, (TileEnergyInfuser) infuser);
}
case GUIID_PLAYERDETECTOR -> {
if (tile instanceof TilePlayerDetectorAdvanced detector) {
return new GUIPlayerDetector(player.inventory, detector);
}
break;
case GUIID_GENERATOR:
TileEntity generator = world.getTileEntity(x, y, z);
if (generator != null && generator instanceof TileGenerator) {
return new GUIGenerator(player.inventory, (TileGenerator) generator);
}
case GUIID_ENERGY_INFUSER -> {
if (tile instanceof TileEnergyInfuser infuser) {
return new GUIEnergyInfuser(player.inventory, infuser);
}
break;
case GUIID_MANUAL:
}
case GUIID_GENERATOR -> {
if (tile instanceof TileGenerator generator) {
return new GUIGenerator(player.inventory, generator);
}
}
case GUIID_MANUAL -> {
return new GUIManual();
case GUIID_DISSENCHANTER:
TileEntity dissenchanter = world.getTileEntity(x, y, z);
if (dissenchanter != null && dissenchanter instanceof TileDissEnchanter) {
return new GUIDissEnchanter(player.inventory, (TileDissEnchanter) dissenchanter);
}
case GUIID_DISSENCHANTER -> {
if (tile instanceof TileDissEnchanter dissenchanter) {
return new GUIDissEnchanter(player.inventory, dissenchanter);
}
break;
case GUIID_DRACONIC_CHEST:
TileEntity containerChest = world.getTileEntity(x, y, z);
if (containerChest != null && containerChest instanceof TileDraconiumChest) {
return new GUIDraconiumChest(player.inventory, (TileDraconiumChest) containerChest);
}
case GUIID_DRACONIC_CHEST -> {
if (tile instanceof TileDraconiumChest draconiumChest) {
return new GUIDraconiumChest(player.inventory, draconiumChest);
}
break;
case GUIID_REACTOR:
TileEntity reactor = world.getTileEntity(x, y, z);
if (reactor != null && reactor instanceof TileReactorCore) {
return new GUIReactor(
player,
(TileReactorCore) reactor,
new ContainerReactor(player, (TileReactorCore) reactor));
}
case GUIID_REACTOR -> {
if (tile instanceof TileReactorCore reactorCore) {
return new GUIReactor(reactorCore, new ContainerReactor(player, reactorCore));
}
break;
case GUIID_TOOL_CONFIG:
}
case GUIID_TOOL_CONFIG -> {
return new GUIToolConfig(
player,
new ContainerAdvTool(player.inventory, new InventoryTool(player, null)));
case GUIID_FLOW_GATE:
return world.getTileEntity(x, y, z) instanceof TileGate
? new GUIFlowGate((TileGate) world.getTileEntity(x, y, z))
: null;
case GUIID_UPGRADE_MODIFIER:
TileEntity containerTemp = world.getTileEntity(x, y, z);
if (containerTemp != null && containerTemp instanceof TileUpgradeModifier) {
}
case GUIID_FLOW_GATE -> {
if (tile instanceof TileGate gate) {
return new GUIFlowGate(gate);
}
}
case GUIID_UPGRADE_MODIFIER -> {
if (tile instanceof TileUpgradeModifier upgradeModifier) {
return new GUIUpgradeModifier(
player.inventory,
(TileUpgradeModifier) containerTemp,
new ContainerUpgradeModifier(player.inventory, (TileUpgradeModifier) containerTemp));
upgradeModifier,
new ContainerUpgradeModifier(player.inventory, upgradeModifier));
}
break;
// case GUIID_CONTAINER_TEMPLATE:
// TileEntity containerTemp = world.getTileEntity(x, y, z);
// if (containerTemp != null && containerTemp instanceof TileContainerTemplate) {
// return new GUIContainerTemplate(player.inventory, (TileContainerTemplate) containerTemp);
// }
// break;
}
}
return null;
@@ -5,36 +5,42 @@ import java.util.List;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import com.brandon3055.brandonscore.client.gui.guicomponents.*;
import com.brandon3055.brandonscore.client.gui.guicomponents.ComponentButton;
import com.brandon3055.brandonscore.client.gui.guicomponents.ComponentCollection;
import com.brandon3055.brandonscore.client.gui.guicomponents.ComponentTextureButton;
import com.brandon3055.brandonscore.client.gui.guicomponents.ComponentTexturedRect;
import com.brandon3055.brandonscore.client.gui.guicomponents.GUIBase;
import com.brandon3055.brandonscore.client.utills.GuiHelper;
import com.brandon3055.brandonscore.common.utills.Utills;
import com.brandon3055.draconicevolution.client.handler.ResourceHandler;
import com.brandon3055.draconicevolution.common.container.ContainerReactor;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore.ReactorState;
/**
* Created by brandon3055 on 30/7/2015.
*/
public class GUIReactor extends GUIBase {
private TileReactorCore reactor;
private ContainerReactor container;
private static boolean showStats = false;
private static boolean showStatistics = false;
private final TileReactorCore core;
private final ContainerReactor container;
public GUIReactor(EntityPlayer player, TileReactorCore reactor, ContainerReactor container) {
public GUIReactor(TileReactorCore core, ContainerReactor container) {
super(container, 248, 222);
this.reactor = reactor;
this.core = core;
this.container = container;
}
@Override
protected ComponentCollection assembleComponents() {
final ResourceLocation widgets = ResourceHandler.getResource("textures/gui/Widgets.png");
collection = new ComponentCollection(0, 0, 248, 222, this);
collection.addComponent(
new ComponentTexturedRect(0, 0, xSize, ySize, ResourceHandler.getResource("textures/gui/Reactor.png")));
@@ -50,7 +56,7 @@ public class GUIReactor extends GUIBase {
this,
"",
StatCollector.translateToLocal("button.de.reactorCharge.txt"),
ResourceHandler.getResource("textures/gui/Widgets.png")))
widgets))
.setName("CHARGE");
collection.addComponent(
new ComponentTextureButton(
@@ -64,7 +70,7 @@ public class GUIReactor extends GUIBase {
this,
"",
StatCollector.translateToLocal("button.de.reactorStart.txt"),
ResourceHandler.getResource("textures/gui/Widgets.png")))
widgets))
.setName("ACTIVATE");
collection.addComponent(
new ComponentTextureButton(
@@ -78,7 +84,7 @@ public class GUIReactor extends GUIBase {
this,
"",
StatCollector.translateToLocal("button.de.reactorStop.txt"),
ResourceHandler.getResource("textures/gui/Widgets.png")))
widgets))
.setName("DEACTIVATE");
collection.addComponent(
new ComponentButton(
@@ -95,10 +101,10 @@ public class GUIReactor extends GUIBase {
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
// Draw I/O Slots
if (reactor.reactorState == TileReactorCore.STATE_OFFLINE) {
if (core.reactorState == ReactorState.OFFLINE) {
RenderHelper.enableGUIStandardItemLighting();
drawTexturedModalRect(guiLeft + 14, guiTop + 139, 14, ySize, 18, 18);
drawTexturedModalRect(guiLeft + 216, guiTop + 139, 32, ySize, 18, 18);
@@ -123,96 +129,86 @@ public class GUIReactor extends GUIBase {
GL11.glColor4f(1f, 1f, 1f, 1f);
// Draw Indicators
double value = Math.min(reactor.reactionTemperature, reactor.maxReactTemperature) / reactor.maxReactTemperature;
double value = Math.min(core.reactionTemperature, core.maxReactTemperature) / core.maxReactTemperature;
int pixOffset = (int) (value * 108);
drawTexturedModalRect(11, 112 - pixOffset, 0, 222, 14, 5);
value = reactor.fieldCharge / reactor.maxFieldCharge;
value = core.fieldCharge / core.maxFieldCharge;
pixOffset = (int) (value * 108);
drawTexturedModalRect(35, 112 - pixOffset, 0, 222, 14, 5);
value = (double) reactor.energySaturation / (double) reactor.maxEnergySaturation;
value = (double) core.energySaturation / (double) core.maxEnergySaturation;
pixOffset = (int) (value * 108);
drawTexturedModalRect(199, 112 - pixOffset, 0, 222, 14, 5);
value = ((double) reactor.convertedFuel) / ((double) reactor.reactorFuel + (double) reactor.convertedFuel);
value = ((double) core.convertedFuel) / ((double) core.reactorFuel + (double) core.convertedFuel);
pixOffset = (int) (value * 108);
drawTexturedModalRect(223, 112 - pixOffset, 0, 222, 14, 5);
GL11.glColor4f(1F, 1F, 1F, 1F);
if (!showStats) {
if (showStatistics) {
ResourceHandler.bindResource("textures/gui/Reactor.png");
for (int i = 1; i <= 10; i++) {
drawTexturedModalRect(63, i * 12, 0, 240, 122, 16);
}
drawStatistics();
} else {
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glTranslated(124, 71, 100);
double scale = 100 / (reactor.getCoreDiameter());
double scale = 100 / (core.getCoreDiameter());
GL11.glScaled(scale, scale, scale);
GL11.glColor4f(1F, 1F, 1F, 1F);
GL11.glDisable(GL11.GL_CULL_FACE);
TileEntityRendererDispatcher.instance.renderTileEntityAt(reactor, -0.5D, -0.5D, -0.5D, 0.0F);
TileEntityRendererDispatcher.instance.renderTileEntityAt(core, -0.5D, -0.5D, -0.5D, 0.0F);
GL11.glPopAttrib();
GL11.glPopMatrix();
} else {
ResourceHandler.bindResource("textures/gui/Reactor.png");
for (int i = 1; i <= 10; i++) drawTexturedModalRect(63, i * 12, 0, 240, 122, 16);
drawStats();
drawStatus();
}
String status = StatCollector.translateToLocal("gui.de.status.txt") + ": "
+ (reactor.reactorState == 0 ? EnumChatFormatting.DARK_GRAY
: reactor.reactorState == 1 ? EnumChatFormatting.RED
: reactor.reactorState == 2 ? EnumChatFormatting.DARK_GREEN : EnumChatFormatting.RED)
+ StatCollector.translateToLocal("gui.de.status" + reactor.reactorState + ".txt");
if (reactor.reactorState == 1 && reactor.canStart())
status = StatCollector.translateToLocal("gui.de.status.txt") + ": "
+ EnumChatFormatting.DARK_GREEN
+ StatCollector.translateToLocal("gui.de.status1_5.txt");
if (!showStats) fontRendererObj.drawString(status, xSize - 5 - fontRendererObj.getStringWidth(status), 125, 0);
}
@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
super.drawScreen(mouseX, mouseY, par3);
List<String> text = new ArrayList<String>();
@SuppressWarnings("unchecked")
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
List<String> text = new ArrayList<>();
if (GuiHelper.isInRect(9, 4, 18, 114, mouseX - guiLeft, mouseY - guiTop)) {
text.add(StatCollector.translateToLocal("gui.de.reactionTemp.txt"));
text.add((int) reactor.reactionTemperature + "C");
text.add((int) core.reactionTemperature + "C");
drawHoveringText(text, mouseX, mouseY, fontRendererObj);
} else if (GuiHelper.isInRect(33, 4, 18, 114, mouseX - guiLeft, mouseY - guiTop)) {
text.add(StatCollector.translateToLocal("gui.de.fieldStrength.txt"));
if (reactor.maxFieldCharge > 0)
text.add(Utills.round(reactor.fieldCharge / reactor.maxFieldCharge * 100D, 100D) + "%");
text.add(
Utills.addCommas((int) reactor.fieldCharge) + " / "
+ Utills.addCommas((int) reactor.maxFieldCharge)); // todo refine or remove
if (core.maxFieldCharge > 0) {
text.add(Utills.round(core.fieldCharge / core.maxFieldCharge * 100D, 100D) + "%");
}
text.add(Utills.addCommas((int) core.fieldCharge) + " / " + Utills.addCommas((int) core.maxFieldCharge));
drawHoveringText(text, mouseX, mouseY, fontRendererObj);
} else if (GuiHelper.isInRect(197, 4, 18, 114, mouseX - guiLeft, mouseY - guiTop)) {
text.add(StatCollector.translateToLocal("gui.de.energySaturation.txt"));
if (reactor.maxEnergySaturation > 0) text.add(
Utills.round((double) reactor.energySaturation / (double) reactor.maxEnergySaturation * 100D, 100D)
+ "%");
text.add(
Utills.addCommas(reactor.energySaturation) + " / " + Utills.addCommas(reactor.maxEnergySaturation)); // todo
// refine
// or
// remove
if (core.maxEnergySaturation > 0) {
text.add(
Utills.round((double) core.energySaturation / (double) core.maxEnergySaturation * 100D, 100D)
+ "%");
}
text.add(Utills.addCommas(core.energySaturation) + " / " + Utills.addCommas(core.maxEnergySaturation));
drawHoveringText(text, mouseX, mouseY, fontRendererObj);
} else if (GuiHelper.isInRect(221, 4, 18, 114, mouseX - guiLeft, mouseY - guiTop)) {
text.add(StatCollector.translateToLocal("gui.de.fuelConversion.txt"));
if (reactor.reactorFuel + reactor.convertedFuel > 0) text.add(
Utills.round(
((double) reactor.convertedFuel + reactor.conversionUnit)
/ ((double) reactor.convertedFuel + (double) reactor.reactorFuel)
* 100D,
100D) + "%");
text.add(reactor.convertedFuel + " / " + (reactor.convertedFuel + reactor.reactorFuel)); // todo refine or
// remove
if (core.reactorFuel + core.convertedFuel > 0) {
text.add(
Utills.round(
((double) core.convertedFuel + core.conversionUnit)
/ ((double) core.convertedFuel + (double) core.reactorFuel)
* 100D,
100D) + "%");
}
text.add(core.convertedFuel + " / " + (core.convertedFuel + core.reactorFuel));
drawHoveringText(text, mouseX, mouseY, fontRendererObj);
}
if (showStats) {
if (showStatistics) {
if (GuiHelper.isInRect(53, 15, 140, 18, mouseX - guiLeft, mouseY - guiTop)) {
text.addAll(
fontRendererObj.listFormattedStringToWidth(
@@ -247,19 +243,18 @@ public class GUIReactor extends GUIBase {
}
}
private void drawStats() {
double inputRate = reactor.fieldDrain / (1D - (reactor.fieldCharge / reactor.maxFieldCharge));
private void drawStatistics() {
double inputRate = core.fieldDrain / (1D - (core.fieldCharge / core.maxFieldCharge));
fontRendererObj.drawString(StatCollector.translateToLocal("gui.de.tempLoad.name"), 55, 16, 0x0000FF);
fontRendererObj.drawString(Utills.round(reactor.tempDrainFactor * 100D, 1D) + "%", 60, 2 + 24, 0);
fontRendererObj.drawString(Utills.round(core.tempDrainFactor * 100D, 1D) + "%", 60, 2 + 24, 0);
fontRendererObj.drawString(StatCollector.translateToLocal("gui.de.mass.name"), 55, 16 + 24, 0x0000FF);
fontRendererObj.drawString(
Utills.round((reactor.reactorFuel + reactor.convertedFuel) / 1296D, 100) + "m^3",
Utills.round((core.reactorFuel + core.convertedFuel) / 1296D, 100) + "m^3",
60,
2 + 2 * 24,
0);
fontRendererObj.drawString(StatCollector.translateToLocal("gui.de.genRate.name"), 55, 16 + 2 * 24, 0x0000FF);
fontRendererObj.drawString(Utills.addCommas((int) reactor.generationRate) + "RF/t", 60, 2 + 3 * 24, 0);
fontRendererObj.drawString(Utills.addCommas((int) core.generationRate) + "RF/t", 60, 2 + 3 * 24, 0);
fontRendererObj
.drawString(StatCollector.translateToLocal("gui.de.fieldInputRate.name"), 55, 16 + 3 * 24, 0x0000FF);
fontRendererObj
@@ -267,38 +262,45 @@ public class GUIReactor extends GUIBase {
fontRendererObj
.drawString(StatCollector.translateToLocal("gui.de.fuelConversion.name"), 55, 16 + 4 * 24, 0x0000FF);
fontRendererObj.drawString(
Utills.addCommas((int) Math.round(reactor.fuelUseRate * 1000000D)) + "nb/t",
Utills.addCommas((int) Math.round(core.fuelUseRate * 1000000D)) + "nb/t",
60,
2 + 5 * 24,
0);
}
private void drawStatus() {
String status = StatCollector.translateToLocal("gui.de.status.txt") + ": ";
switch (core.reactorState) {
case OFFLINE -> status += EnumChatFormatting.DARK_GRAY;
case STARTING, STOPPING -> status += EnumChatFormatting.RED;
case ONLINE -> status += EnumChatFormatting.DARK_GREEN;
case INVALID -> status += EnumChatFormatting.DARK_RED;
}
status += core.reactorState.toLocalizedString(core.canStart());
fontRendererObj.drawString(status, xSize - 5 - fontRendererObj.getStringWidth(status), 125, 0);
}
@Override
public void updateScreen() {
if (reactor.reactorState == TileReactorCore.STATE_INVALID
|| reactor.reactorState == TileReactorCore.STATE_OFFLINE
|| reactor.reactorState == TileReactorCore.STATE_STOP)
collection.getComponent("DEACTIVATE").setEnabled(false);
else collection.getComponent("DEACTIVATE").setEnabled(true);
if ((reactor.reactorState == TileReactorCore.STATE_OFFLINE
|| (reactor.reactorState == TileReactorCore.STATE_STOP && !reactor.canStart())) && reactor.canCharge())
collection.getComponent("CHARGE").setEnabled(true);
else collection.getComponent("CHARGE").setEnabled(false);
if ((reactor.reactorState == TileReactorCore.STATE_START || reactor.reactorState == TileReactorCore.STATE_STOP)
&& reactor.canStart())
collection.getComponent("ACTIVATE").setEnabled(true);
else collection.getComponent("ACTIVATE").setEnabled(false);
collection.getComponent("DEACTIVATE")
.setEnabled(core.reactorState == ReactorState.STARTING || core.reactorState == ReactorState.ONLINE);
collection.getComponent("CHARGE").setEnabled(
(core.reactorState == ReactorState.OFFLINE
|| (core.reactorState == ReactorState.STOPPING && !core.canStart())) && core.canCharge());
collection.getComponent("ACTIVATE").setEnabled(
(core.reactorState == ReactorState.STARTING || core.reactorState == ReactorState.STOPPING)
&& core.canStart());
super.updateScreen();
}
@Override
public void buttonClicked(int id, int button) {
super.buttonClicked(id, button);
if (id < 3) container.sendObjectToServer(null, 20, id);
else if (id == 3) {
showStats = !showStats;
((ComponentButton) collection.getComponent("STATS")).hoverText = showStats
if (id < 3) {
container.sendObjectToServer(null, 20, id);
} else if (id == 3) {
showStatistics = !showStatistics;
((ComponentButton) collection.getComponent("STATS")).hoverText = showStatistics
? StatCollector.translateToLocal("button.de.statsHide.txt")
: StatCollector.translateToLocal("button.de.statsShow.txt");
}
@@ -3,7 +3,6 @@ package com.brandon3055.draconicevolution.client.render.particle;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import org.lwjgl.opengl.GL11;
@@ -11,7 +10,6 @@ import com.brandon3055.draconicevolution.client.handler.ResourceHandler;
import com.brandon3055.draconicevolution.common.blocks.multiblock.IReactorPart;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorEnergyInjector;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorStabilizer;
import cpw.mods.fml.relauncher.Side;
@@ -23,16 +21,10 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ParticleReactorBeam extends EntityFX {
/**
* Particle Type 0 = Energy Ring, 1 = single particle
*/
private boolean renderParticle = true;
private TileEntity tile;
private boolean isInjectorBeam = false;
private final TileEntity tile;
public ParticleReactorBeam(TileEntity tile) {
super(tile.getWorldObj(), tile.xCoord + 0.5, tile.yCoord + 0.5, tile.zCoord + 0.5, 0.0D, 0.0D, 0.0D);
super(tile.getWorldObj(), tile.xCoord + 0.5, tile.yCoord + 0.5, tile.zCoord + 0.5, 0.0, 0.0, 0.0);
this.tile = tile;
this.particleRed = 1F;
this.particleGreen = 1F;
@@ -43,16 +35,16 @@ public class ParticleReactorBeam extends EntityFX {
this.motionZ = 0.0D;
this.particleMaxAge = 4;
this.setSize(1F, 1F);
isInjectorBeam = tile instanceof TileReactorEnergyInjector;
}
public void update(boolean render) {
for (this.renderParticle = render; this.particleMaxAge - this.particleAge < 4; ++this.particleMaxAge) {}
public void update() {
if (this.particleMaxAge - this.particleAge < 4) {
this.particleMaxAge = this.particleAge + 4;
}
}
@Override
public void onUpdate() {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
@@ -65,137 +57,102 @@ public class ParticleReactorBeam extends EntityFX {
@Override
public void renderParticle(Tessellator tessellator, float partialTick, float rotX, float rotXZ, float rotZ,
float rotYZ, float rotXY) {
if (!((IReactorPart) tile).isActive()) return;
if (!((IReactorPart) tile).isActive()) {
return;
}
tessellator.draw();
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F);
float xx = (float) (this.prevPosX + (this.posX - this.prevPosX) * (double) partialTick - interpPosX);
float yy = (float) (this.prevPosY + (this.posY - this.prevPosY) * (double) partialTick - interpPosY);
float zz = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * (double) partialTick - interpPosZ);
GL11.glTranslated((double) xx, (double) yy, (double) zz);
double shiftX = this.prevPosX + (this.posX - this.prevPosX) * partialTick - interpPosX;
double shiftY = this.prevPosY + (this.posY - this.prevPosY) * partialTick - interpPosY;
double shiftZ = this.prevPosZ + (this.posZ - this.prevPosZ) * partialTick - interpPosZ;
GL11.glTranslated(shiftX, shiftY, shiftZ);
// Common Fields
MultiblockHelper.TileLocation master = ((IReactorPart) tile).getMaster();
float offsetX = (float) (master.posX - tile.xCoord);
float offsetY = (float) ((double) master.posY - tile.yCoord);
float offsetZ = (float) (master.posZ - tile.zCoord);
float length = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ);
MultiblockHelper.TileLocation master = ((IReactorPart) tile).getMasterLocation();
double offsetX = master.posX - tile.xCoord;
double offsetY = master.posY - tile.yCoord;
double offsetZ = master.posZ - tile.zCoord;
double offsetLength = Math.sqrt(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ);
double diagonalLength = Math.sqrt(offsetX * offsetX + offsetZ * offsetZ);
// Rotate beam to face target
float f7 = MathHelper.sqrt_float(offsetX * offsetX + offsetZ * offsetZ);
GL11.glRotatef(
(float) (-Math.atan2((double) offsetZ, (double) offsetX)) * 180.0F / (float) Math.PI - 90.0F,
0.0F,
1.0F,
0.0F);
GL11.glRotatef(
(float) (-Math.atan2((double) f7, (double) offsetY)) * 180.0F / (float) Math.PI - 90.0F,
1.0F,
0.0F,
0.0F);
GL11.glRotated(Math.toDegrees(-Math.atan2(offsetZ, offsetX)) - 90.0, 0.0, 1.0, 0.0);
GL11.glRotated(Math.toDegrees(-Math.atan2(diagonalLength, offsetY)) - 90.0, 1.0, 0.0, 0.0);
TileReactorCore reactor = ((IReactorPart) tile).getMaster().getTileEntity(worldObj) instanceof TileReactorCore
? (TileReactorCore) ((IReactorPart) tile).getMaster().getTileEntity(worldObj)
: null;
if (tile instanceof TileReactorStabilizer && reactor != null)
renderStabilizerEffect(tessellator, reactor, offsetX, offsetY, offsetZ, length, partialTick);
else if (reactor != null) {
TileReactorCore core = ((IReactorPart) tile).getMaster();
if (tile instanceof TileReactorStabilizer && core != null)
renderStabilizerEffect(tessellator, core, offsetLength, partialTick);
else if (core != null) {
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glTranslated(0, 0, 0.3);
// GL11.glPushMatrix();
GL11.glRotatef(((float) particleAge + partialTick) * 20F, 0, 0, 1);
GL11.glTranslated(0.0, 0.0, 0.3);
GL11.glRotatef(((float) particleAge + partialTick) * 20F, 0F, 0F, 1F);
ResourceHandler.bindResource("textures/particle/reactorEnergyBeam.png");
// float sizeOrigin = 0.5F;
// float sizeTarget = 0.2F;
float sizeOrigin = 0.5F;
double sizeOrigin = 0.5;
int color = 0xFF2200;
int alpha = (int) (200D * reactor.renderSpeed);
int alpha = (int) (200.0 * core.renderSpeed);
float speed = 20F;
float texV2 = 0.0F + ((float) particleAge + partialTick) * 0.01F * speed;
float texV1 = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ)
+ ((float) particleAge + partialTick) * 0.01F * speed;
double speed = 20.0;
double texV2 = ((double) particleAge + partialTick) * 0.01 * speed;
double texV1 = offsetLength + texV2;
tessellator.startDrawing(5);
tessellator.startDrawing(GL11.GL_TRIANGLE_STRIP);
tessellator.setBrightness(200);
float sizeTarget = 0.1F;
double sizeTarget = 0.1;
byte b0 = 16;
length = 0F;
for (int i = 0; i <= b0; ++i) {
float verX = MathHelper.sin((float) (i % b0) * (float) Math.PI * 2.3F / (float) b0) * sizeTarget;
float verY = MathHelper.cos((float) (i % b0) * (float) Math.PI * 2.3F / (float) b0) * sizeTarget;
float texU = (float) (i % b0) * 1.0F / (float) b0;
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), 0);
final int raysCount = 16;
for (int ray = 0; ray <= raysCount; ++ray) {
double texU = (double) ray / raysCount;
double verX = Math.sin(texU * Math.PI * 2.3) * sizeTarget;
double verY = Math.cos(texU * Math.PI * 2.3) * sizeTarget;
tessellator.addVertexWithUV(
(double) (verX * sizeOrigin),
(double) (verY * sizeOrigin),
-0.55D,
(double) texU,
(double) texV1);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), alpha);
tessellator
.addVertexWithUV((double) verX, (double) verY, (double) length, (double) texU, (double) texV2);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF, 0);
tessellator.addVertexWithUV(verX * sizeOrigin, verY * sizeOrigin, -0.55, texU, texV1);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF, alpha);
tessellator.addVertexWithUV(verX, verY, offsetLength, texU, texV2);
}
length = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ)
- (float) (reactor.getCoreDiameter() / 2D)
- 0.3F;
sizeTarget = (float) (reactor.getCoreDiameter() / 2 * 0.2D);
sizeOrigin = 0.1F / sizeTarget;
offsetLength -= core.getCoreRadius() + 0.3;
sizeTarget = core.getCoreRadius() * 0.2;
sizeOrigin = 0.1 / sizeTarget;
for (int i = 0; i <= b0; ++i) {
float verX = MathHelper.sin((float) (i % b0) * (float) Math.PI * 2.13F / (float) b0) * sizeTarget;
float verY = MathHelper.cos((float) (i % b0) * (float) Math.PI * 2.13F / (float) b0) * sizeTarget;
float texU = (float) (i % b0) * 1.0F / (float) b0;
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), alpha);
for (int ray = 0; ray <= raysCount; ray++) {
double texU = (double) ray / raysCount;
double verX = Math.sin(texU * Math.PI * 2.13) * sizeTarget;
double verY = Math.cos(texU * Math.PI * 2.13) * sizeTarget;
tessellator.addVertexWithUV(
(double) (verX * sizeOrigin),
(double) (verY * sizeOrigin),
0.0D,
(double) texU,
(double) texV1);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF, alpha);
tessellator.addVertexWithUV(verX * sizeOrigin, verY * sizeOrigin, 0.0, texU, texV1);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), 0);
tessellator
.addVertexWithUV((double) verX, (double) verY, (double) length, (double) texU, (double) texV2);
tessellator.addVertexWithUV(verX, verY, offsetLength, texU, texV2);
}
tessellator.draw();
// GL11.glPopMatrix();
GL11.glRotatef(((float) particleAge + partialTick) * -30F, 0, 0, 1);
GL11.glRotatef(((float) particleAge + partialTick) * -30F, 0F, 0F, 1F);
tessellator.startDrawing(5);
tessellator.startDrawing(GL11.GL_TRIANGLE_STRIP);
tessellator.setBrightness(200);
color = 0xFF4400;
sizeTarget = (float) (reactor.getCoreDiameter() / 2 * 0.6D);
sizeOrigin = 0.1F / sizeTarget;
length += 0.4F;
sizeTarget = core.getCoreRadius() * 0.6;
sizeOrigin = 0.1 / sizeTarget;
offsetLength += 0.4;
GL11.glTranslated(0, 0, -0.1);
for (int i = 0; i <= b0; ++i) {
float verX = MathHelper.sin((float) (i % b0) * (float) Math.PI * 2.13F / (float) b0) * sizeTarget;
float verY = MathHelper.cos((float) (i % b0) * (float) Math.PI * 2.13F / (float) b0) * sizeTarget;
float texU = (float) (i % b0) * 1.0F / (float) b0;
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), alpha / 2);
for (int ray = 0; ray <= raysCount; ray++) {
double texU = (double) ray / raysCount;
double verX = Math.sin(texU * Math.PI * 2.13F) * sizeTarget;
double verY = Math.cos(texU * Math.PI * 2.13F) * sizeTarget;
tessellator.addVertexWithUV(
(double) (verX * sizeOrigin),
(double) (verY * sizeOrigin),
0.0D,
(double) texU,
(double) texV1);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), 0);
tessellator
.addVertexWithUV((double) verX, (double) verY, (double) length, (double) texU, (double) texV2);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF, alpha / 2);
tessellator.addVertexWithUV(verX * sizeOrigin, verY * sizeOrigin, 0.0, texU, texV1);
tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF, 0);
tessellator.addVertexWithUV(verX, verY, offsetLength, texU, texV2);
}
tessellator.draw();
@@ -208,44 +165,28 @@ public class ParticleReactorBeam extends EntityFX {
tessellator.startDrawingQuads();
}
private void renderStabilizerEffect(Tessellator tessellator, TileReactorCore reactor, float offsetX, float offsetY,
float offsetZ, float length, float partialTick) {
private void renderStabilizerEffect(Tessellator tessellator, TileReactorCore core, double offsetLength,
float partialTick) {
GL11.glShadeModel(GL11.GL_SMOOTH);
// Draw Beams
GL11.glPushMatrix();
GL11.glTranslated(0, 0, -0.35);
GL11.glTranslated(0.0, 0.0, -0.35);
ResourceHandler.bindResource("textures/particle/reactorBeam.png");
drawBeam(
tessellator,
reactor,
1F,
0.355F,
0.8F,
offsetX,
offsetY,
offsetZ,
particleAge,
partialTick,
true,
false,
0x00ffff);
drawBeam(tessellator, core, 1.0, 0.355, 0.8, offsetLength, partialTick, true, false, 0x00ffff);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslated(0, 0, 0.45);
float coreSize = (float) (reactor.getCoreDiameter() / 2) * 0.9F;
float s = 0.355F;
GL11.glTranslated(0.0, 0.0, 0.45);
double coreSize = core.getCoreRadius() * 0.9;
double scale = 0.355;
drawBeam(
tessellator,
reactor,
s / coreSize,
core,
scale / coreSize,
coreSize,
length - (float) (reactor.getCoreDiameter() / 2.5D),
offsetX,
offsetY,
offsetZ,
particleAge,
offsetLength - core.getCoreDiameter() / 2.5,
offsetLength,
partialTick,
false,
false,
@@ -253,37 +194,21 @@ public class ParticleReactorBeam extends EntityFX {
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslated(0, 0, -0.35);
drawBeam(
tessellator,
reactor,
1F,
0.263F,
0.8F,
offsetX,
offsetY,
offsetZ,
particleAge,
partialTick,
true,
true,
0xff6600);
GL11.glTranslated(0.0, 0.0, -0.35);
drawBeam(tessellator, core, 1.0, 0.263, 0.8, offsetLength, partialTick, true, true, 0xff6600);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslated(0, 0, 0.45);
coreSize = (float) (reactor.getCoreDiameter() / 2) * 0.4F;
s = 0.263F;
GL11.glTranslated(0.0, 0.0, 0.45);
coreSize = core.getCoreRadius() * 0.4;
scale = 0.263;
drawBeam(
tessellator,
reactor,
s / coreSize,
core,
scale / coreSize,
coreSize,
length - 0.5F,
offsetX,
offsetY,
offsetZ,
particleAge,
offsetLength - 0.5,
offsetLength,
partialTick,
false,
true,
@@ -297,160 +222,36 @@ public class ParticleReactorBeam extends EntityFX {
* Size Origin is the fraction of size start Target So if size target is 10 and size origin is 0.5 origin will
* actually be 5
*/
private void drawBeam(Tessellator tessellator, TileReactorCore reactor, float sizeOrigin, float sizeTarget,
float length, float offsetX, float offsetY, float offsetZ, int tick, float partialTick,
boolean reverseTransparency, boolean reverseDirection, int color) {
float speed = 3F;
float texV2 = -0.1F + ((float) tick + partialTick) * (reverseDirection ? -0.01F : 0.01F) * speed;
float texV1 = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ) / 32.0F
+ ((float) tick + partialTick) * (reverseDirection ? -0.01F : 0.01F) * speed;
private void drawBeam(Tessellator tessellator, TileReactorCore core, double sizeOrigin, double sizeTarget,
double length, double offsetLength, float partialTick, boolean reverseTransparency,
boolean reverseDirection, int color) {
final double speed = 3.0;
final double tickOffset = ((double) particleAge + partialTick) * (reverseDirection ? -0.01 : 0.01) * speed;
tessellator.startDrawing(5);
double texV1 = offsetLength / 32.0 + tickOffset;
double texV2 = -0.1 + tickOffset;
tessellator.startDrawing(GL11.GL_TRIANGLE_STRIP);
tessellator.setBrightness(200);
byte b0 = 16;
for (int i = 0; i <= b0; ++i) {
float verX = MathHelper.sin((float) (i % b0) * (float) Math.PI * 2.13325F / (float) b0) * sizeTarget;
float verY = MathHelper.cos((float) (i % b0) * (float) Math.PI * 2.13325F / (float) b0) * sizeTarget;
float texU = (float) (i % b0) * 1.0F / (float) b0;
final int raysCount = 16;
for (int ray = 0; ray <= raysCount; ++ray) {
double texU = (double) ray / raysCount;
double verX = Math.sin(texU * Math.PI * 2.13325) * sizeTarget;
double verY = Math.cos(texU * Math.PI * 2.13325) * sizeTarget;
tessellator.setColorRGBA(
(color & 0xFF0000) >> 16,
(color & 0xFF00) >> 8,
(color & 0xFF),
reverseTransparency ? 0 : (int) (255D * reactor.renderSpeed));
tessellator.addVertexWithUV(
(double) (verX * sizeOrigin),
(double) (verY * sizeOrigin),
0.0D,
(double) texU,
(double) texV1);
color & 0xFF,
reverseTransparency ? 0 : (int) (255.0 * core.renderSpeed));
tessellator.addVertexWithUV(verX * sizeOrigin, verY * sizeOrigin, 0.0, texU, texV1);
tessellator.setColorRGBA(
(color & 0xFF0000) >> 16,
(color & 0xFF00) >> 8,
(color & 0xFF),
reverseTransparency ? (int) (255D * reactor.renderSpeed) : 0);
tessellator.addVertexWithUV((double) verX, (double) verY, (double) length, (double) texU, (double) texV2);
color & 0xFF,
reverseTransparency ? (int) (255.0 * core.renderSpeed) : 0);
tessellator.addVertexWithUV(verX, verY, length, texU, texV2);
}
tessellator.draw();
}
}
// @Override
// public void renderParticle(Tessellator tessellator, float partialTick, float rotX, float rotXZ, float rotZ, float
// rotYZ, float rotXY) {
// if (!((IIsSlave)tile).isActive()) return;
// tessellator.draw();
// GL11.glPushMatrix();
// GL11.glDisable(GL11.GL_CULL_FACE);
// GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F);
//
// float xx = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)partialTick - interpPosX);
// float yy = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)partialTick - interpPosY);
// float zz = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTick - interpPosZ);
// GL11.glTranslated((double)xx, (double)yy, (double)zz);
//
// //Common Fields
// MultiblockHelper.TileLocation master = ((IIsSlave)tile).getMaster();
// float offsetX = (float)(master.posX - tile.xCoord);
// float offsetY = (float)((double)master.posY - tile.yCoord);
// float offsetZ = (float)(master.posZ - tile.zCoord);
// float length = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ);
//
//
// //Rotate beam to face target
// float f7 = MathHelper.sqrt_float(offsetX * offsetX + offsetZ * offsetZ);
// GL11.glRotatef((float) (-Math.atan2((double) offsetZ, (double) offsetX)) * 180.0F / (float) Math.PI - 90.0F, 0.0F,
// 1.0F, 0.0F);
// GL11.glRotatef((float)(-Math.atan2((double)f7, (double)offsetY)) * 180.0F / (float)Math.PI - 90.0F, 1.0F, 0.0F,
// 0.0F);
//
// if (tile instanceof TileReactorStabilizer) renderStabilizerEffect(tessellator, offsetX, offsetY, offsetZ, length,
// partialTick);
// else {
// GL11.glShadeModel(GL11.GL_SMOOTH);
// GL11.glTranslated(0, 0, 0.3);
// //GL11.glPushMatrix();
// GL11.glRotatef(((float)particleAge + partialTick)*20F, 0, 0, 1);
// ResourceHandler.bindResource("textures/particle/reactorEnergyBeam.png");
//// float sizeOrigin = 0.5F;
//// float sizeTarget = 0.2F;
// float sizeTarget = 0.2F;
// float sizeOrigin = 0.5F;
//
// int color = 0xFF2200;
// int alpha = 200;
// length -= 1;
//
// float speed = 20F;
// float texV2 = 0.0F + ((float)particleAge + partialTick) * 0.01F * speed;
// float texV1 = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ) +
// ((float)particleAge + partialTick) * 0.01F * speed;
//
// tessellator.startDrawing(5);
// tessellator.setBrightness(200);
//
// byte b0 = 16;
// for (int i = 0; i <= b0; ++i)
// {
// float verX = MathHelper.sin((float)(i % b0) * (float)Math.PI * 2.13F / (float)b0) * sizeTarget;
// float verY = MathHelper.cos((float)(i % b0) * (float)Math.PI * 2.13F / (float)b0) * sizeTarget;
// float texU = (float)(i % b0) * 1.0F / (float)b0;
// tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), alpha);
//
// tessellator.addVertexWithUV((double)(verX * sizeOrigin), (double)(verY * sizeOrigin), 0.0D, (double)texU,
// (double)texV1);
// tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), 0);
// tessellator.addVertexWithUV((double)verX, (double)verY, (double)length, (double)texU, (double)texV2);
// }
//
// sizeTarget = 0.1F;
//
// length = 0F;
// for (int i = 0; i <= b0; ++i)
// {
// float verX = MathHelper.sin((float)(i % b0) * (float)Math.PI * 2.3F / (float)b0) * sizeTarget;
// float verY = MathHelper.cos((float)(i % b0) * (float)Math.PI * 2.3F / (float)b0) * sizeTarget;
// float texU = (float)(i % b0) * 1.0F / (float)b0;
// tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), 0);
//
// tessellator.addVertexWithUV((double)(verX * sizeOrigin), (double)(verY * sizeOrigin), -0.55D, (double)texU,
// (double)texV1);
// tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), alpha);
// tessellator.addVertexWithUV((double)verX, (double)verY, (double)length, (double)texU, (double)texV2);
// }
//
// tessellator.draw();
// //GL11.glPopMatrix();
// GL11.glRotatef(((float)particleAge + partialTick)*-30F, 0, 0, 1);
//
// tessellator.startDrawing(5);
// tessellator.setBrightness(200);
// color = 0xFF4400;
// sizeOrigin = 0.15F;
// sizeTarget = 0.6F;
// length = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ) - 1;
// GL11.glTranslated(0, 0, -0.1);
//
// for (int i = 0; i <= b0; ++i)
// {
// float verX = MathHelper.sin((float)(i % b0) * (float)Math.PI * 2.13F / (float)b0) * sizeTarget;
// float verY = MathHelper.cos((float)(i % b0) * (float)Math.PI * 2.13F / (float)b0) * sizeTarget;
// float texU = (float)(i % b0) * 1.0F / (float)b0;
// tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), alpha/2);
//
// tessellator.addVertexWithUV((double)(verX * sizeOrigin), (double)(verY * sizeOrigin), 0.0D, (double)texU,
// (double)texV1);
// tessellator.setColorRGBA((color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, (color & 0xFF), 0);
// tessellator.addVertexWithUV((double)verX, (double)verY, (double)length, (double)texU, (double)texV2);
// }
//
// tessellator.draw();
// GL11.glShadeModel(GL11.GL_FLAT);
// }
//
// GL11.glPopMatrix();
// GL11.glEnable(GL11.GL_CULL_FACE);
// ResourceHandler.bindDefaultParticles();
// tessellator.startDrawingQuads();
// }
@@ -17,10 +17,10 @@ import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.Til
*/
public class RenderTileEnergyPylon extends TileEntitySpecialRenderer {
private static final ResourceLocation model_texture = new ResourceLocation(
private static final ResourceLocation modelTexture = new ResourceLocation(
References.MODID.toLowerCase(),
"textures/models/pylon_sphere_texture.png");
private IModelCustom model;
private final IModelCustom model;
public RenderTileEnergyPylon() {
model = AdvancedModelLoader
@@ -30,10 +30,13 @@ public class RenderTileEnergyPylon extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) {
if (tile == null || !(tile instanceof TileEnergyPylon)) return;
TileEnergyPylon pylon = (TileEnergyPylon) tile;
if (!pylon.active) return;
float scale = pylon.modelScale + (timeSinceLastTick *= !pylon.reciveEnergy ? -0.01F : 0.01F);
if (!(tile instanceof TileEnergyPylon pylon)) {
return;
}
if (!pylon.active) {
return;
}
float scale = pylon.modelScale + (timeSinceLastTick *= !pylon.isReceivingEnergy ? -0.01F : 0.01F);
float rotation = pylon.modelRotation + (timeSinceLastTick / 2F);
GL11.glPushMatrix();
@@ -48,7 +51,7 @@ public class RenderTileEnergyPylon extends TileEntitySpecialRenderer {
GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F);
bindTexture(model_texture);
bindTexture(modelTexture);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0F);
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0F);
GL11.glDisable(GL11.GL_LIGHTING);
@@ -59,37 +62,10 @@ public class RenderTileEnergyPylon extends TileEntitySpecialRenderer {
GL11.glDepthMask(false);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200F, 200F);
GL11.glPushMatrix();
float scale1 = scale % 1F;
GL11.glScalef(scale1, scale1, scale1);
GL11.glRotatef(rotation * 0.5F, 0F, -1F, -0.5F);
GL11.glColor4d(1D, 1D, 1D, 1F - (scale1));
model.renderAll();
GL11.glPopMatrix();
GL11.glPushMatrix();
float scale2 = (scale + 0.25F) % 1F;
GL11.glScalef(scale2, scale2, scale2);
GL11.glRotatef(rotation * 0.5F, 0F, -1F, -0.5F);
GL11.glColor4f(1F, 1F, 1F, 1F - (scale2));
model.renderAll();
GL11.glPopMatrix();
GL11.glPushMatrix();
float scale3 = (scale + 0.5F) % 1F;
GL11.glScalef(scale3, scale3, scale3);
GL11.glRotatef(rotation * 0.5F, 0F, -1F, -0.5F);
GL11.glColor4f(1F, 1F, 1F, 1F - (scale3));
model.renderAll();
GL11.glPopMatrix();
GL11.glPushMatrix();
float scale4 = (scale + 0.75F) % 1F;
GL11.glScalef(scale4, scale4, scale4);
GL11.glRotatef(rotation * 0.5F, 0F, -1F, -0.5F);
GL11.glColor4f(1F, 1F, 1F, 1F - (scale4));
model.renderAll();
GL11.glPopMatrix();
renderPass(scale % 1F, rotation);
renderPass((scale + 0.25F) % 1F, rotation);
renderPass((scale + 0.5F) % 1F, rotation);
renderPass((scale + 0.75F) % 1F, rotation);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_TEXTURE_2D);
@@ -100,5 +76,12 @@ public class RenderTileEnergyPylon extends TileEntitySpecialRenderer {
GL11.glPopMatrix();
}
// private void renderSphere()
private void renderPass(float scale, float rotation) {
GL11.glPushMatrix();
GL11.glScalef(scale, scale, scale);
GL11.glRotatef(rotation * 0.5F, 0F, -1F, -0.5F);
GL11.glColor4f(1F, 1F, 1F, 1F - scale);
model.renderAll();
GL11.glPopMatrix();
}
}
@@ -20,49 +20,38 @@ import cpw.mods.fml.client.FMLClientHandler;
*/
public class RenderTileEnergyStorageCore extends TileEntitySpecialRenderer {
private static final ResourceLocation iner_model_texture = new ResourceLocation(
private static final ResourceLocation InnerModelTexture = new ResourceLocation(
References.MODID.toLowerCase(),
"textures/models/power_sphere_layer_1.png");
private static final ResourceLocation outer_model_texture = new ResourceLocation(
private static final ResourceLocation OuterModelTexture = new ResourceLocation(
References.MODID.toLowerCase(),
"textures/models/power_sphere_layer_2.png");
private IModelCustom iner_model;
private final IModelCustom innerModel;
public RenderTileEnergyStorageCore() {
iner_model = AdvancedModelLoader
innerModel = AdvancedModelLoader
.loadModel(new ResourceLocation(References.MODID.toLowerCase(), "models/power_sphere_layer_1.obj"));
}
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) {
if (tile == null || !(tile instanceof TileEnergyStorageCore)) return;
TileEnergyStorageCore core = (TileEnergyStorageCore) tile;
if (!core.isOnline()) return;
if (!(tile instanceof TileEnergyStorageCore core)) {
return;
}
if (!core.isOnline()) {
return;
}
float scale = 0;
float rotation = core.modelRotation + (timeSinceLastTick / 2F);
switch (core.getTier()) {
case 0:
scale = 0.7F;
break;
case 1:
scale = 1.2F;
break;
case 2:
scale = 1.7F;
break;
case 3:
scale = 2.5F;
break;
case 4:
scale = 3.5F;
break;
case 5:
scale = 4.5F;
break;
case 6:
scale = 5.5F;
break;
case 0 -> scale = 0.7F;
case 1 -> scale = 1.2F;
case 2 -> scale = 1.7F;
case 3 -> scale = 2.5F;
case 4 -> scale = 3.5F;
case 5 -> scale = 4.5F;
case 6 -> scale = 5.5F;
}
GL11.glPushMatrix();
@@ -71,44 +60,29 @@ public class RenderTileEnergyStorageCore extends TileEntitySpecialRenderer {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
FMLClientHandler.instance().getClient().getTextureManager().bindTexture(iner_model_texture);
FMLClientHandler.instance().getClient().getTextureManager().bindTexture(InnerModelTexture);
double colour = (double) ((TileEnergyStorageCore) tile).getEnergyStored()
/ (double) ((TileEnergyStorageCore) tile).getMaxEnergyStored();
double color = (double) core.getEnergyStored() / core.getMaxEnergyStored();
float brightness = (float) Math.abs(Math.sin((float) Minecraft.getSystemTime() / 3000f) * 100f);
colour = 1f - colour;
color = 1f - color;
GL11.glScalef(scale, scale, scale);
GL11.glPushMatrix();
GL11.glRotatef(rotation, 0F, 1F, 0.5F);
GL11.glColor4d(1F, colour * 0.3f, colour * 0.7f, 1F);
GL11.glColor4d(1F, color * 0.3f, color * 0.7f, 1F);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 80f + brightness, 80f + brightness);
iner_model.renderAll();
innerModel.renderAll();
GL11.glPopMatrix();
// GL11.glPushMatrix();
// GL11.glScalef(0.8F, 0.8F, 0.8F);
// GL11.glColor4d(1F, 1f, 0.2f, 1F);
// GL11.glRotatef(rotation, 0F, 1F, 0.5F);
// //iner_model.renderAll();
// GL11.glPopMatrix();
//
// GL11.glPushMatrix();
// GL11.glScalef(0.9F, 0.9F, 0.9F);
// GL11.glColor4d(1F, 0f, 0.2f, 1F);
// GL11.glRotatef(rotation, 0F, 1F, 0.5F);
// //iner_model.renderAll();
// GL11.glPopMatrix();
GL11.glScalef(1.1F, 1.1F, 1.1F);
GL11.glDepthMask(false);
FMLClientHandler.instance().getClient().getTextureManager().bindTexture(outer_model_texture);
FMLClientHandler.instance().getClient().getTextureManager().bindTexture(OuterModelTexture);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200F, 200F);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glRotatef(rotation * 0.5F, 0F, -1F, -0.5F);
GL11.glColor4f(0.5F, 2F, 2F, 0.7F);
iner_model.renderAll();
innerModel.renderAll();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_LIGHTING);
@@ -31,9 +31,9 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
private static final ResourceLocation modelTexture = new ResourceLocation(
References.MODID.toLowerCase(),
"textures/models/stabilizer_sphere.png");
private IModelCustom stabilizerSphereModel;
private final IModelCustom stabilizerSphereModel;
private float pxl = 1F / 64;
private final float pixel = 1F / 64F;
public RenderTileParticleGen() {
stabilizerSphereModel = AdvancedModelLoader
@@ -54,8 +54,8 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
public void renderBlock(TileParticleGenerator tl, float f3) {
Tessellator tessellator = Tessellator.instance;
boolean inverted = tl.inverted;
boolean stabilizerMode = tl.stabalizerMode;
boolean inverted = tl.isInverted;
boolean stabilizerMode = tl.isInStabilizerMode;
GL11.glPushMatrix();
@@ -104,7 +104,7 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
drawEnergyBeam(tessellator, tl, f3);
}
if (tl.beam_enabled) preRenderBeam(tessellator, tl, f3);
if (tl.isBeamEnabled) preRenderBeam(tessellator, tl, f3);
}
private void drawEnergyBeam(Tessellator tess, TileParticleGenerator gen, float f) {
@@ -144,12 +144,12 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
GL11.glColor4f(0.0F, 2.0F, 0.0F, 1F);
GL11.glTranslated(0.5, 0, 0.5);
GL11.glScalef(0.4F, 0.4F, 0.4F);
if (!tile.stabalizerMode) {
float red = (float) tile.beam_red / 255F;
float green = (float) tile.beam_green / 255F;
float blue = (float) tile.beam_blue / 255F;
if (!tile.isInStabilizerMode) {
float red = (float) tile.beamRed / 255F;
float green = (float) tile.beamGreen / 255F;
float blue = (float) tile.beamBlue / 255F;
GL11.glColor4f(red, green, blue, 1F);
GL11.glScalef(tile.beam_scale, tile.beam_scale, tile.beam_scale);
GL11.glScalef(tile.beamScale, tile.beamScale, tile.beamScale);
}
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200, 200);
@@ -166,10 +166,10 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDepthMask(false);
GL11.glColor4f(0.0F, 1.0F, 1.0F, 0.5F);
if (!tile.stabalizerMode) {
float red = (float) tile.beam_red / 255F;
float green = (float) tile.beam_green / 255F;
float blue = (float) tile.beam_blue / 255F;
if (!tile.isInStabilizerMode) {
float red = (float) tile.beamRed / 255F;
float green = (float) tile.beamGreen / 255F;
float blue = (float) tile.beamBlue / 255F;
GL11.glColor4f(red, green, blue, 0.5F);
}
GL11.glEnable(GL11.GL_BLEND);
@@ -217,10 +217,10 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
double d17 = 0.5D + Math.sin(rotation + 3.9269908169872414D) * scale;
double d19 = 0.5D + Math.cos(rotation + 5.497787143782138D) * scale;
double d21 = 0.5D + Math.sin(rotation + 5.497787143782138D) * scale;
double height = (double) (length);
double height = length;
double texXMin = 0.0D;
double texXMax = 1.0D;
double d28 = (double) (-1.0F + upMot);
double d28 = -1.0F + upMot;
double texHeight = (double) (length) * (0.5D / scale) + d28;
tess.addVertexWithUV(x + d7, y + height, z + d9, texXMax, texHeight);
@@ -297,10 +297,10 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
double d12 = 0.8D;
double d14 = 0.8D;
double d16 = 0.8D;
double d18 = (double) (length);
double d18 = length;
double d20 = 0.0D;
double d22 = 1.0D;
double d24 = (double) (-1.0F + upMot);
double d24 = -1.0F + upMot;
double d26 = (double) (length) + d24;
tess.addVertexWithUV(x + d30, y + d18, z + d4, d22, d26);
tess.addVertexWithUV(x + d30, y, z + d4, d22, d24);
@@ -333,16 +333,16 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
private void drawCornerCube(Tessellator tess, float x, float y, float z, float FP, boolean inverted,
boolean stabalizerMode) {
float srcXMin = inverted ? 38F * pxl : 32F * pxl;
float srcXMin = inverted ? 38F * pixel : 32F * pixel;
float srcYMin = 0F;
float srcXMax = inverted ? 44F * pxl : 38F * pxl;
float srcYMax = 6 * pxl;
float srcXMax = inverted ? 44F * pixel : 38F * pixel;
float srcYMax = 6 * pixel;
// float FP = 0.6F; //Scale
float FN = 1F - FP;
if (stabalizerMode) {
srcXMin = 44F * pxl;
srcXMax = 50F * pxl;
srcXMin = 44F * pixel;
srcXMax = 50F * pixel;
}
// X+
@@ -385,8 +385,8 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
private void drawBeamX(Tessellator tess, float x, float y, float z, float FP) {
float srcXMin = 0;
float srcYMin = 0F;
float srcXMax = 32F * pxl;
float srcYMax = 4 * pxl;
float srcXMax = 32F * pixel;
float srcYMax = 4 * pixel;
float FN = 1F - FP;
float XX = 0.9F;
@@ -420,8 +420,8 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
private void drawBeamY(Tessellator tess, float x, float y, float z, float FP) {
float srcXMin = 0;
float srcYMin = 0F;
float srcXMax = 32F * pxl;
float srcYMax = 4 * pxl;
float srcXMax = 32F * pixel;
float srcYMax = 4 * pixel;
float FN = 1F - FP;
float XX = 0.9F;
@@ -455,8 +455,8 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
private void drawBeamZ(Tessellator tess, float x, float y, float z, float FP) {
float srcXMin = 0;
float srcYMin = 0F;
float srcXMax = 32F * pxl;
float srcYMax = 4 * pxl;
float srcXMax = 32F * pixel;
float srcYMax = 4 * pixel;
float FN = 1F - FP;
float XX = 0.9F;
@@ -491,17 +491,17 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
GL11.glPushMatrix();
GL11.glTranslated(0, 0.5, 0.5);
GL11.glRotatef(90F + gen.beam_pitch, 1F, 0F, 0F);
GL11.glRotatef(90F + gen.beamPitch, 1F, 0F, 0F);
GL11.glTranslated(0, 0, -0.5);
GL11.glTranslated(0.5, 0, 0);
GL11.glRotatef(gen.beam_yaw, 0F, 0F, 1F);
GL11.glRotatef(gen.beamYaw, 0F, 0F, 1F);
GL11.glTranslated(-0.5, 0, 0);
renderBeam(tess, gen, f);
GL11.glPopMatrix();
if (gen.render_core) {
if (gen.shouldRenderCore) {
GL11.glPushMatrix();
GL11.glTranslated(0, 0.5, 0);
renderStabilizerSphere(gen);
@@ -513,10 +513,10 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
int x = 0;
int y = 0;
int z = 0;
double length = tile.beam_length;
float red = (float) tile.beam_red / 255F;
float green = (float) tile.beam_green / 255F;
float blue = (float) tile.beam_blue / 255F;
double length = tile.beamLength;
float red = (float) tile.beamRed / 255F;
float green = (float) tile.beamGreen / 255F;
float blue = (float) tile.beamBlue / 255F;
GL11.glPushMatrix();
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
@@ -533,14 +533,13 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
// float time = (float)tile.getWorldObj().getTotalWorldTime() + f;
float time = tile.rotation + f;
float upMot = -time * 0.2F - (float) MathHelper.floor_float(-time * 0.1F);
float rotValue = tile.beam_rotation * (tile.rotation + f * 0.5F);
double rotation = rotValue;
double rotation = tile.beamRotation * (tile.rotation + f * 0.5F);
tess.startDrawingQuads();
tess.setBrightness(200);
tess.setColorRGBA(tile.beam_red, tile.beam_green, tile.beam_blue, 32);
tess.setColorRGBA(tile.beamRed, tile.beamGreen, tile.beamBlue, 32);
double scale = (double) tile.beam_scale * 0.2D;
double scale = (double) tile.beamScale * 0.2D;
double d7 = 0.5D + Math.cos(rotation + 2.356194490192345D) * scale; // x point 1
double d9 = 0.5D + Math.sin(rotation + 2.356194490192345D) * scale; // z point 1
double d11 = 0.5D + Math.cos(rotation + (Math.PI / 4D)) * scale; // x point 2
@@ -549,31 +548,30 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
double d17 = 0.5D + Math.sin(rotation + 3.9269908169872414D) * scale;
double d19 = 0.5D + Math.cos(rotation + 5.497787143782138D) * scale;
double d21 = 0.5D + Math.sin(rotation + 5.497787143782138D) * scale;
double height = (double) (length);
double texXMin = 0.0D;
double texXMax = 1.0D;
double d28 = (double) (-1.0F + upMot);
double texHeight = (double) (length) * (0.5D / scale) + d28;
double d28 = -1.0F + upMot;
double texHeight = length * (0.5D / scale) + d28;
tess.addVertexWithUV(x + d7, y + height, z + d9, texXMax, texHeight);
tess.addVertexWithUV(x + d7, y + length, z + d9, texXMax, texHeight);
tess.addVertexWithUV(x + d7, y, z + d9, texXMax, d28);
tess.addVertexWithUV(x + d11, y, z + d13, texXMin, d28);
tess.addVertexWithUV(x + d11, y + height, z + d13, texXMin, texHeight);
tess.addVertexWithUV(x + d11, y + length, z + d13, texXMin, texHeight);
tess.addVertexWithUV(x + d19, y + height, z + d21, texXMax, texHeight);
tess.addVertexWithUV(x + d19, y + length, z + d21, texXMax, texHeight);
tess.addVertexWithUV(x + d19, y, z + d21, texXMax, d28);
tess.addVertexWithUV(x + d15, y, z + d17, texXMin, d28);
tess.addVertexWithUV(x + d15, y + height, z + d17, texXMin, texHeight);
tess.addVertexWithUV(x + d15, y + length, z + d17, texXMin, texHeight);
tess.addVertexWithUV(x + d11, y + height, z + d13, texXMax, texHeight);
tess.addVertexWithUV(x + d11, y + length, z + d13, texXMax, texHeight);
tess.addVertexWithUV(x + d11, y, z + d13, texXMax, d28);
tess.addVertexWithUV(x + d19, y, z + d21, texXMin, d28);
tess.addVertexWithUV(x + d19, y + height, z + d21, texXMin, texHeight);
tess.addVertexWithUV(x + d19, y + length, z + d21, texXMin, texHeight);
tess.addVertexWithUV(x + d15, y + height, z + d17, texXMax, texHeight);
tess.addVertexWithUV(x + d15, y + length, z + d17, texXMax, texHeight);
tess.addVertexWithUV(x + d15, y, z + d17, texXMax, d28);
tess.addVertexWithUV(x + d7, y, z + d9, texXMin, d28);
tess.addVertexWithUV(x + d7, y + height, z + d9, texXMin, texHeight);
tess.addVertexWithUV(x + d7, y + length, z + d9, texXMin, texHeight);
rotation += 0.77f;
d7 = 0.5D + Math.cos(rotation + 2.356194490192345D) * scale;
@@ -586,29 +584,29 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
d21 = 0.5D + Math.sin(rotation + 5.497787143782138D) * scale;
d28 = (-1F + (upMot * 1));
texHeight = (double) (length) * (0.5D / scale) + d28;
texHeight = length * (0.5D / scale) + d28;
tess.setColorRGBA_F(red, green, blue, 1f);
tess.addVertexWithUV(x + d7, y + height, z + d9, texXMax, texHeight);
tess.addVertexWithUV(x + d7, y + length, z + d9, texXMax, texHeight);
tess.addVertexWithUV(x + d7, y, z + d9, texXMax, d28);
tess.addVertexWithUV(x + d11, y, z + d13, texXMin, d28);
tess.addVertexWithUV(x + d11, y + height, z + d13, texXMin, texHeight);
tess.addVertexWithUV(x + d11, y + length, z + d13, texXMin, texHeight);
tess.addVertexWithUV(x + d19, y + height, z + d21, texXMax, texHeight);
tess.addVertexWithUV(x + d19, y + length, z + d21, texXMax, texHeight);
tess.addVertexWithUV(x + d19, y, z + d21, texXMax, d28);
tess.addVertexWithUV(x + d15, y, z + d17, texXMin, d28);
tess.addVertexWithUV(x + d15, y + height, z + d17, texXMin, texHeight);
tess.addVertexWithUV(x + d15, y + length, z + d17, texXMin, texHeight);
tess.addVertexWithUV(x + d11, y + height, z + d13, texXMax, texHeight);
tess.addVertexWithUV(x + d11, y + length, z + d13, texXMax, texHeight);
tess.addVertexWithUV(x + d11, y, z + d13, texXMax, d28);
tess.addVertexWithUV(x + d19, y, z + d21, texXMin, d28);
tess.addVertexWithUV(x + d19, y + height, z + d21, texXMin, texHeight);
tess.addVertexWithUV(x + d19, y + length, z + d21, texXMin, texHeight);
tess.addVertexWithUV(x + d15, y + height, z + d17, texXMax, texHeight);
tess.addVertexWithUV(x + d15, y + length, z + d17, texXMax, texHeight);
tess.addVertexWithUV(x + d15, y, z + d17, texXMax, d28);
tess.addVertexWithUV(x + d7, y, z + d9, texXMin, d28);
tess.addVertexWithUV(x + d7, y + height, z + d9, texXMin, texHeight);
tess.addVertexWithUV(x + d7, y + length, z + d9, texXMin, texHeight);
tess.draw();
GL11.glPushMatrix();
@@ -620,10 +618,10 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glDepthMask(false);
GL11.glTranslated(0.5, 0, 0.5);
GL11.glScalef(tile.beam_scale, 1f, tile.beam_scale);
GL11.glScalef(tile.beamScale, 1f, tile.beamScale);
GL11.glTranslated(-0.5, -0, -0.5);
tess.startDrawingQuads();
tess.setColorRGBA(tile.beam_red, tile.beam_green, tile.beam_blue, 32);
tess.setColorRGBA(tile.beamRed, tile.beamGreen, tile.beamBlue, 32);
double d30 = 0.2D;
double d4 = 0.2D;
double d6 = 0.8D;
@@ -632,27 +630,26 @@ public class RenderTileParticleGen extends TileEntitySpecialRenderer {
double d12 = 0.8D;
double d14 = 0.8D;
double d16 = 0.8D;
double d18 = (double) (length);
double d20 = 0.0D;
double d22 = 1D;
double d24 = (double) (-1.0F + upMot);
double d26 = (double) (length) + d24;
tess.addVertexWithUV(x + d30, y + d18, z + d4, d22, d26);
double d24 = -1.0F + upMot;
double d26 = length + d24;
tess.addVertexWithUV(x + d30, y + length, z + d4, d22, d26);
tess.addVertexWithUV(x + d30, y, z + d4, d22, d24);
tess.addVertexWithUV(x + d6, y, z + d8, d20, d24);
tess.addVertexWithUV(x + d6, y + d18, z + d8, d20, d26);
tess.addVertexWithUV(x + d14, y + d18, z + d16, d22, d26);
tess.addVertexWithUV(x + d6, y + length, z + d8, d20, d26);
tess.addVertexWithUV(x + d14, y + length, z + d16, d22, d26);
tess.addVertexWithUV(x + d14, y, z + d16, d22, d24);
tess.addVertexWithUV(x + d10, y, z + d12, d20, d24);
tess.addVertexWithUV(x + d10, y + d18, z + d12, d20, d26);
tess.addVertexWithUV(x + d6, y + d18, z + d8, d22, d26);
tess.addVertexWithUV(x + d10, y + length, z + d12, d20, d26);
tess.addVertexWithUV(x + d6, y + length, z + d8, d22, d26);
tess.addVertexWithUV(x + d6, y, z + d8, d22, d24);
tess.addVertexWithUV(x + d14, y, z + d16, d20, d24);
tess.addVertexWithUV(x + d14, y + d18, z + d16, d20, d26);
tess.addVertexWithUV(x + d10, y + d18, z + d12, d22, d26);
tess.addVertexWithUV(x + d14, y + length, z + d16, d20, d26);
tess.addVertexWithUV(x + d10, y + length, z + d12, d22, d26);
tess.addVertexWithUV(x + d10, y, z + d12, d22, d24);
tess.addVertexWithUV(x + d30, y, z + d4, d20, d24);
tess.addVertexWithUV(x + d30, y + d18, z + d4, d20, d26);
tess.addVertexWithUV(x + d30, y + length, z + d4, d20, d26);
tess.draw();
GL11.glPopMatrix();
@@ -27,35 +27,23 @@ public class RenderTileReactorCore extends TileEntitySpecialRenderer {
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) {
TileReactorCore tile = (TileReactorCore) tileEntity;
// tile.renderList.clear();
TileReactorCore core = (TileReactorCore) tileEntity;
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
renderReactorCore(tile, partialTick);
// for (MultiblockHelper.TileOffset offset : tile.stabilizerLocations){
// if (!(offset.getTileEntity(tileEntity) instanceof TileReactorStabilizer)) continue;
// GL11.glPushMatrix();
//
// TileReactorStabilizer stabilizer = (TileReactorStabilizer)offset.getTileEntity(tileEntity);
// GL11.glTranslated(-offset.offsetX, -offset.offsetY, -offset.offsetZ);
// //RenderTileReactorStabilizer.renderCore(stabilizer, partialTick);
// //RenderTileReactorStabilizer.renderEffects(stabilizer, partialTick);
//
// GL11.glPopMatrix();
// }
renderReactorCore(core, partialTick);
GL11.glPopMatrix();
}
public void renderReactorCore(TileReactorCore tile, float partialTick) {
float rotation = (tile.renderRotation * 0.2F) + (partialTick * (tile.renderSpeed * 0.2F));
double ff = tile.maxFieldCharge > 0 ? tile.fieldCharge / tile.maxFieldCharge : 0;
double r = ff < 0.5 ? 1 - (ff * 2) : 0;
double g = ff > 0.5 ? (ff - 0.5) * 2 : 0;
double b = ff * 2;
double a = ff < 0.1 ? (ff * 10) : 1;
public void renderReactorCore(TileReactorCore core, float partialTick) {
float rotation = core.renderRotation * 0.2F + partialTick * (core.renderSpeed * 0.2F);
double fieldChargePercentage = core.maxFieldCharge > 0 ? core.fieldCharge / core.maxFieldCharge : 0;
double r = fieldChargePercentage < 0.5 ? 1 - fieldChargePercentage * 2 : 0;
double g = fieldChargePercentage > 0.5 ? (fieldChargePercentage - 0.5) * 2 : 0;
double b = fieldChargePercentage * 2;
double a = fieldChargePercentage < 0.1 ? fieldChargePercentage * 10 : 1;
// Pre Render
GL11.glPushMatrix();
@@ -65,7 +53,7 @@ public class RenderTileReactorCore extends TileEntitySpecialRenderer {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200F, 200F);
// Render inner
if (tile.reactorFuel + tile.convertedFuel < 144) {
if (core.reactorFuel + core.convertedFuel < 144) {
ResourceHandler.bindResource("textures/blocks/draconic_block_blank.png");
GL11.glPushMatrix();
GL11.glScaled(0.1, 0.1, 0.1);
@@ -77,8 +65,8 @@ public class RenderTileReactorCore extends TileEntitySpecialRenderer {
GL11.glColor4d(1, 1, 1, 1);
GL11.glRotatef(rotation, 0.5F, 1F, 0.5F);
GL11.glScaled(0.5, 0.5, 0.5);
double r3 = tile.getCoreDiameter();
GL11.glScaled(r3, r3, r3);
double diameter = core.getCoreDiameter();
GL11.glScaled(diameter, diameter, diameter);
reactorModel.renderAll();
// Mid Render
@@ -87,10 +75,11 @@ public class RenderTileReactorCore extends TileEntitySpecialRenderer {
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0F);
if (tile.reactionTemperature < 2000) {
if (core.reactionTemperature < 2000) {
ResourceHandler.bindResource("textures/blocks/draconic_block_blank.png");
if (tile.reactionTemperature > 1000)
GL11.glColor4d(1F, 1F, 1F, 1D - ((tile.reactionTemperature - 1000) / 1000D));
if (core.reactionTemperature > 1000) {
GL11.glColor4d(1F, 1F, 1F, 1D - (core.reactionTemperature - 1000) / 1000D);
}
reactorModel.renderAll();
}
@@ -2,6 +2,7 @@ package com.brandon3055.draconicevolution.client.render.tile;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@@ -17,38 +18,40 @@ public class RenderTileReactorEnergyInjector extends TileEntitySpecialRenderer {
public static ModelReactorEnergyInjector modelReactorEnergyInjector = new ModelReactorEnergyInjector();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) {
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTick) {
if (!(tile instanceof TileReactorEnergyInjector injector)) {
return;
}
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
renderCore((TileReactorEnergyInjector) tileEntity, partialTick);
renderCore(injector);
GL11.glPopMatrix();
}
public static void renderCore(TileReactorEnergyInjector tile, float partialTick) {
public static void renderCore(TileReactorEnergyInjector injector) {
GL11.glPushMatrix();
float scale = (1F / 16F);
switch (tile.facingDirection) {
case 1:
GL11.glRotated(180, -1, 0, 0);
break;
case 2:
GL11.glRotated(90, 1, 0, 0);
break;
case 3:
GL11.glRotated(90, -1, 0, 0);
break;
case 4:
GL11.glRotated(90, 0, 0, -1);
break;
case 5:
GL11.glRotated(90, 0, 0, 1);
int angle = 90;
ForgeDirection axis = injector.facing;
switch (injector.facing) {
case UP -> {
angle = 180;
axis = ForgeDirection.WEST;
}
case SOUTH -> axis = ForgeDirection.WEST;
case NORTH -> axis = ForgeDirection.EAST;
case WEST -> axis = ForgeDirection.NORTH;
case EAST -> axis = ForgeDirection.SOUTH;
}
if (injector.facing != ForgeDirection.DOWN) {
GL11.glRotated(angle, axis.offsetX, axis.offsetY, axis.offsetZ);
}
ResourceHandler.bindResource("textures/models/ModelReactorPowerInjector.png");
modelReactorEnergyInjector.render(null, tile.modelIllumination, 0F, 0F, 0F, 0F, scale);
modelReactorEnergyInjector.render(null, injector.modelIllumination, 0F, 0F, 0F, 0F, scale);
GL11.glPopMatrix();
}
@@ -2,6 +2,7 @@ package com.brandon3055.draconicevolution.client.render.tile;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
@@ -19,120 +20,49 @@ public class RenderTileReactorStabilizer extends TileEntitySpecialRenderer {
public static ModelReactorStabilizerCore modelStabilizerCore = new ModelReactorStabilizerCore();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick) {
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTick) {
if (!(tile instanceof TileReactorStabilizer stabilizer)) {
return;
}
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
renderCore((TileReactorStabilizer) tileEntity, partialTick);
// renderEffects((TileReactorStabilizer) tileEntity, partialTick);
renderCore(stabilizer, partialTick);
GL11.glPopMatrix();
}
public static void renderCore(TileReactorStabilizer tile, float partialTick) {
public static void renderCore(TileReactorStabilizer stabilizer, float partialTick) {
GL11.glPushMatrix();
float scale = (1F / 16F);
float coreRotation = tile.coreRotation + (partialTick * tile.coreSpeed);
float ringRotation = tile.ringRotation + (partialTick * tile.ringSpeed);
float coreRotation = stabilizer.coreRotation + (partialTick * stabilizer.coreSpeed);
float ringRotation = stabilizer.ringRotation + (partialTick * stabilizer.ringSpeed);
switch (tile.facingDirection) {
case 0:
GL11.glRotated(90, -1, 0, 0);
break;
case 1:
GL11.glRotated(90, 1, 0, 0);
break;
case 3:
GL11.glRotated(180, 1, 0, 0);
break;
case 4:
GL11.glRotated(90, 0, 1, 0);
break;
case 5:
GL11.glRotated(90, 0, -1, 0);
int angle = 90;
ForgeDirection axis = stabilizer.facing;
switch (stabilizer.facing) {
case DOWN -> axis = ForgeDirection.WEST;
case SOUTH -> {
angle = 180;
axis = ForgeDirection.EAST;
}
case UP -> axis = ForgeDirection.EAST;
case WEST -> axis = ForgeDirection.UP;
case EAST -> axis = ForgeDirection.DOWN;
}
if (stabilizer.facing != ForgeDirection.NORTH) {
GL11.glRotated(angle, axis.offsetX, axis.offsetY, axis.offsetZ);
}
ResourceHandler.bindResource("textures/models/reactorStabilizerCore.png");
modelStabilizerCore.render(null, coreRotation, tile.modelIllumination, 0F, 0F, 0F, scale);
modelStabilizerCore.render(null, coreRotation, stabilizer.modelIllumination, 0F, 0F, 0F, scale);
ResourceHandler.bindResource("textures/models/reactorStabilizerRing.png");
GL11.glRotated(90, 1, 0, 0);
GL11.glTranslated(0, -0.58, 0);
GL11.glScaled(0.95, 0.95, 0.95);
GL11.glRotatef(ringRotation, 0, 1, 0);
modelStabilizerRing.render(null, -70F, tile.modelIllumination, 0F, 0F, 0F, scale);
modelStabilizerRing.render(null, -70F, stabilizer.modelIllumination, 0F, 0F, 0F, scale);
GL11.glPopMatrix();
}
// public static void renderEffects(TileReactorStabilizer tile, float partialTick) {
// if (tile.isValid)
// {
// //Common Fields
// MultiblockHelper.TileLocation master = tile.masterLocation;
// float offsetX = (float)(master.posX - tile.xCoord);
// float offsetY = (float)((double)master.posY - tile.yCoord);
// float offsetZ = (float)(master.posZ - tile.zCoord);
// float length = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ);
//
// Tessellator tessellator = Tessellator.instance;
//
// //Pre Render
// GL11.glPushMatrix();
//// RenderHelper.disableStandardItemLighting();
// GL11.glDisable(GL11.GL_CULL_FACE);
// GL11.glShadeModel(GL11.GL_SMOOTH);
// GL11.glEnable(GL11.GL_BLEND);
// OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
// GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F);
// GL11.glDisable(GL11.GL_LIGHTING);
// GL11.glDepthMask(false);
//
// //Rotate beam to face target
// float f7 = MathHelper.sqrt_float(offsetX * offsetX + offsetZ * offsetZ);
// GL11.glRotatef((float) (-Math.atan2((double) offsetZ, (double) offsetX)) * 180.0F / (float) Math.PI - 90.0F,
// 0.0F, 1.0F, 0.0F);
// GL11.glRotatef((float)(-Math.atan2((double)f7, (double)offsetY)) * 180.0F / (float)Math.PI - 90.0F, 1.0F, 0.0F,
// 0.0F);
//
//
// //Draw Beams
// GL11.glPushMatrix();
// GL11.glTranslated(0, 0, -0.35);
// ResourceHandler.bindTexture(new ResourceLocation("textures/entity/endercrystal/endercrystal_beam.png"));
//// drawBeam(tessellator, 1F, 0.355F, 0.8F, offsetX, offsetY, offsetZ, tile.tick, partialTick, true, false);
// GL11.glPopMatrix();
//
// GL11.glPushMatrix();
// GL11.glTranslated(0, 0, 0.4526);
// float coreSize = 1.1F;
// float s = 0.355F;
//// drawBeam(tessellator, s/coreSize, coreSize, length - 0.5F, offsetX, offsetY, offsetZ, tile.tick, partialTick,
// false, false);
// GL11.glPopMatrix();
//
//// GL11.glPushMatrix();
//// GL11.glTranslated(0, 0, -0.35);
//// ResourceHandler.bindTexture(new ResourceLocation("textures/entity/endercrystal/endercrystal_beam.png"));
//// drawBeam(tessellator, 1F, 0.26F, 0.8F, offsetX, offsetY, offsetZ, tile.tick, partialTick, true, true);
//// GL11.glPopMatrix();
////
//// GL11.glPushMatrix();
//// GL11.glTranslated(0, 0, 0.4526);
//// coreSize = 1.1F;
//// s = 0.263F;
//// drawBeam(tessellator, s/coreSize, coreSize, length - 0.5F, offsetX, offsetY, offsetZ, tile.tick, partialTick,
// false, true);
//// GL11.glPopMatrix();
//
// //Post Render
// GL11.glDepthMask(true);
// GL11.glEnable(GL11.GL_LIGHTING);
// GL11.glEnable(GL11.GL_CULL_FACE);
// GL11.glShadeModel(GL11.GL_FLAT);
//// RenderHelper.enableStandardItemLighting();
// GL11.glDisable(GL11.GL_BLEND);
// GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
// GL11.glPopMatrix();
// }
// }
}
@@ -1,5 +1,6 @@
package com.brandon3055.draconicevolution.common.blocks;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
@@ -26,9 +27,10 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 27/08/2014.
*/
public class CKeyStone extends BlockDE {
public class CKeyStone extends BlockDE implements ITileEntityProvider {
private IIcon blockIcon1;
@SideOnly(Side.CLIENT)
private IIcon blockIconActive;
public CKeyStone() {
this.setBlockUnbreakable();
@@ -43,43 +45,41 @@ public class CKeyStone extends BlockDE {
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileCKeyStone();
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "key_stone_inactive");
blockIcon1 = iconRegister.registerIcon(References.RESOURCESPREFIX + "key_stone_active");
blockIconActive = iconRegister.registerIcon(References.RESOURCESPREFIX + "key_stone_active");
}
@Override
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
if (side == 0 || side == 1) return Blocks.furnace.getIcon(side, meta);
else return blockIcon1;
public IIcon getIcon(int side, int metadata) {
return side == 0 || side == 1 ? Blocks.furnace.getIcon(side, metadata) : blockIconActive;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
if (side == 0 || side == 1) return Blocks.furnace.getIcon(side, 0);
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
: null;
if (tile != null) return tile.isActivated ? blockIcon1 : blockIcon;
else return blockIcon;
if (side == 0 || side == 1) {
return Blocks.furnace.getIcon(side, 0);
}
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileCKeyStone keyStone) {
return keyStone.isActivated ? blockIconActive : blockIcon;
}
return blockIcon;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
: null;
if (tile != null) return tile.onActivated(player.getHeldItem(), player);
return false;
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
TileEntity tile = world.getTileEntity(x, y, z);
return tile instanceof TileCKeyStone keyStone && keyStone.onActivated(player.getHeldItem(), player);
}
@Override
@@ -94,26 +94,16 @@ public class CKeyStone extends BlockDE {
@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int meta) {
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
: null;
if (tile != null) return tile.isActivated ? 15 : 0;
return 0;
}
@Override
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int meta) {
return 0;
TileEntity tile = world.getTileEntity(x, y, z);
return tile instanceof TileCKeyStone keyStone && keyStone.isActivated ? 15 : 0;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
TileCKeyStone tile = world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileCKeyStone ? (TileCKeyStone) world.getTileEntity(x, y, z)
: null;
if (tile != null) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileCKeyStone keyStone) {
ItemStack key = new ItemStack(ModItems.key);
ItemNBTHelper.setInteger(key, "KeyCode", tile.getKeyCode());
ItemNBTHelper.setInteger(key, "KeyCode", keyStone.getKeyCode());
ItemNBTHelper.setInteger(key, "X", x);
ItemNBTHelper.setInteger(key, "Y", y);
ItemNBTHelper.setInteger(key, "Z", z);
@@ -123,8 +113,7 @@ public class CKeyStone extends BlockDE {
}
@Override
public boolean isBlockSolid(IBlockAccess p_149747_1_, int p_149747_2_, int p_149747_3_, int p_149747_4_,
int p_149747_5_) {
public boolean isBlockSolid(IBlockAccess world, int x, int y, int z, int side) {
return true;
}
@@ -3,6 +3,7 @@ package com.brandon3055.draconicevolution.common.blocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
@@ -11,6 +12,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.draconicevolution.DraconicEvolution;
import com.brandon3055.draconicevolution.client.gui.GuiHandler;
@@ -26,7 +28,7 @@ import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ParticleGenerator extends BlockDE {
public class ParticleGenerator extends BlockDE implements ITileEntityProvider {
public static Block instance;
@@ -38,45 +40,45 @@ public class ParticleGenerator extends BlockDE {
ModBlocks.register(this);
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "machine_side");
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float p_149727_7_,
float p_149727_8_, float p_149727_9_) {
if (world.getBlockMetadata(x, y, z) == 1) return false;
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
if (world.getBlockMetadata(x, y, z) == 1) {
return false;
}
if (player.getHeldItem() != null && player.getHeldItem().getItem() == Items.paper) {
TileEntity tile = world.getTileEntity(x, y, z);
TileParticleGenerator gen = (tile != null && tile instanceof TileParticleGenerator)
? (TileParticleGenerator) tile
: null;
ItemStack stack = player.getHeldItem();
if (gen != null && stack.hasTagCompound() && stack.getTagCompound().hasKey("particles_enabled")) {
gen.setBlockNBT(stack.getTagCompound());
return true;
if (tile instanceof TileParticleGenerator particleGenerator) {
ItemStack stack = player.getHeldItem();
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("particles_enabled")) {
particleGenerator.setBlockNBT(stack.getTagCompound());
return true;
}
}
}
if (player.isSneaking()) {
if (activateEnergyStorageCore(world, x, y, z, player)) return true;
TileEntity tile = world.getTileEntity(x, y, z);
TileParticleGenerator gen = (tile != null && tile instanceof TileParticleGenerator)
? (TileParticleGenerator) tile
: null;
if (gen != null) {
gen.toggleInverted();
if (activateEnergyStorageCore(world, x, y, z, player)) {
return true;
}
} else
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileParticleGenerator particleGenerator) {
particleGenerator.toggleInverted();
}
} else {
FMLNetworkHandler.openGui(player, DraconicEvolution.instance, GuiHandler.GUIID_PARTICLEGEN, world, x, y, z);
}
return true;
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public int getRenderType() {
return -1;
}
@@ -84,11 +86,8 @@ public class ParticleGenerator extends BlockDE {
@Override
public void onNeighborBlockChange(final World world, final int x, final int y, final int z, final Block block) {
TileEntity tile = world.getTileEntity(x, y, z);
TileParticleGenerator gen = (tile != null && tile instanceof TileParticleGenerator)
? (TileParticleGenerator) tile
: null;
if (gen != null) {
gen.signal = world.isBlockIndirectlyGettingPowered(x, y, z);
if (tile instanceof TileParticleGenerator particleGenerator) {
particleGenerator.hasRedstoneSignal = world.isBlockIndirectlyGettingPowered(x, y, z);
world.markBlockForUpdate(x, y, z);
}
}
@@ -98,44 +97,45 @@ public class ParticleGenerator extends BlockDE {
return true;
}
@SideOnly(Side.CLIENT)
@Override
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) {
if (world.isRemote) {
Random rand = world.rand;
float modifier = 0.1F;
float SCALE = 1;
double spawnX = x + 0.5D;
double spawnY = y + 0.5D;
double spawnZ = z + 0.5D;
@SideOnly(Side.CLIENT)
public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int metadata) {
if (!world.isRemote) {
return;
}
Random rand = world.rand;
float modifier = 0.1F;
float scale = 1;
double spawnX = x + 0.5D;
double spawnY = y + 0.5D;
double spawnZ = z + 0.5D;
for (int i = 0; i < 100; i++) {
float MX = modifier - ((2f * modifier) * rand.nextFloat());
float MY = modifier - ((2f * modifier) * rand.nextFloat());
float MZ = modifier - ((2f * modifier) * rand.nextFloat());
for (int i = 0; i < 100; i++) {
float motionX = modifier - ((2f * modifier) * rand.nextFloat());
float motionY = modifier - ((2f * modifier) * rand.nextFloat());
float motionZ = modifier - ((2f * modifier) * rand.nextFloat());
{
ParticleCustom particle = new ParticleCustom(
world,
spawnX,
spawnY,
spawnZ,
MX,
MY,
MZ,
SCALE,
false,
1);
particle.red = rand.nextInt(255);
particle.green = rand.nextInt(255);
particle.blue = rand.nextInt(255);
particle.maxAge = rand.nextInt(10);
particle.fadeTime = 20;
particle.fadeLength = 20;
particle.gravity = 0F;
{
ParticleCustom particle = new ParticleCustom(
world,
spawnX,
spawnY,
spawnZ,
motionX,
motionY,
motionZ,
scale,
false,
1);
particle.red = rand.nextInt(255);
particle.green = rand.nextInt(255);
particle.blue = rand.nextInt(255);
particle.maxAge = rand.nextInt(10);
particle.fadeTime = 20;
particle.fadeLength = 20;
particle.gravity = 0F;
ParticleHandler.spawnCustomParticle(particle);
}
ParticleHandler.spawnCustomParticle(particle);
}
}
}
@@ -146,8 +146,7 @@ public class ParticleGenerator extends BlockDE {
}
@Override
public boolean shouldSideBeRendered(IBlockAccess p_149646_1_, int p_149646_2_, int p_149646_3_, int p_149646_4_,
int p_149646_5_) {
public boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, int side) {
return false;
}
@@ -157,81 +156,54 @@ public class ParticleGenerator extends BlockDE {
}
@Override
public boolean hasTileEntity(int meta) {
public boolean hasTileEntity(int metadata) {
return true;
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileParticleGenerator();
}
private boolean activateEnergyStorageCore(World world, int x, int y, int z, EntityPlayer player) {
for (int x1 = x - 11; x1 <= x + 11; x1++) {
if (world.getBlock(x1, y, z) == ModBlocks.energyStorageCore) {
TileEnergyStorageCore tile = (world.getTileEntity(x1, y, z) != null
&& world.getTileEntity(x1, y, z) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(x1, y, z)
: null;
if (tile != null && !tile.isOnline()) {
if (player.capabilities.isCreativeMode) {
if (!tile.creativeActivate()) {
if (world.isRemote) player.addChatComponentMessage(
new ChatComponentTranslation("msg.energyStorageCoreUTA.txt"));
return false;
}
} else {
if (!tile.tryActivate()) {
if (world.isRemote) player.addChatComponentMessage(
new ChatComponentTranslation("msg.energyStorageCoreUTA.txt"));
return false;
}
}
return true;
}
}
}
for (int z1 = z - 11; z1 <= z + 11; z1++) {
if (world.getBlock(x, y, z1) == ModBlocks.energyStorageCore) {
TileEnergyStorageCore tile = (world.getTileEntity(x, y, z1) != null
&& world.getTileEntity(x, y, z1) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(x, y, z1)
: null;
if (tile != null && !tile.isOnline()) {
if (player.capabilities.isCreativeMode) {
if (!tile.creativeActivate()) {
if (world.isRemote) player.addChatComponentMessage(
new ChatComponentTranslation("msg.energyStorageCoreUTA.txt"));
return false;
}
} else {
if (!tile.tryActivate()) {
if (world.isRemote) player.addChatComponentMessage(
new ChatComponentTranslation("msg.energyStorageCoreUTA.txt"));
return false;
}
}
return true;
final ForgeDirection[] horizontalDirections = new ForgeDirection[] { ForgeDirection.EAST, ForgeDirection.SOUTH,
ForgeDirection.WEST, ForgeDirection.NORTH };
for (ForgeDirection direction : horizontalDirections) {
for (int distance = 1; distance <= TileEnergyStorageCore.STABILIZER_SEARCH_DISTANCE; distance++) {
int coreX = x + direction.offsetX * distance;
int coreZ = z + direction.offsetZ * distance;
if (world.getBlock(coreX, y, coreZ) == ModBlocks.energyStorageCore) {
return tryActivateEnergyStorageCore(world, coreX, y, coreZ, player);
}
}
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int meta) {
if (meta == 1) {
TileEntity tile = world.getTileEntity(x, y, z);
TileParticleGenerator gen = (tile != null && tile instanceof TileParticleGenerator)
? (TileParticleGenerator) tile
: null;
if (gen != null && gen.getMaster() != null) {
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
// LogHelper.info("deActivate");
gen.getMaster().isStructureStillValid(true);
private boolean tryActivateEnergyStorageCore(World world, int coreX, int coreY, int coreZ, EntityPlayer player) {
TileEntity tile = world.getTileEntity(coreX, coreY, coreZ);
if (tile instanceof TileEnergyStorageCore core) {
if (core.tryActivate(player.capabilities.isCreativeMode)) {
return true;
}
if (world.isRemote) {
player.addChatComponentMessage(new ChatComponentTranslation("msg.energyStorageCoreUTA.txt"));
}
}
super.breakBlock(world, x, y, z, p_149749_5_, meta);
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
if (metadata == 1) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileParticleGenerator particleGenerator) {
if (particleGenerator.getMaster() != null) {
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
particleGenerator.getMaster().validateStructure(true);
}
}
}
super.breakBlock(world, x, y, z, blockBroken, metadata);
}
}
@@ -1,6 +1,7 @@
package com.brandon3055.draconicevolution.common.blocks.machine;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
@@ -18,11 +19,18 @@ import com.brandon3055.draconicevolution.common.lib.References;
import com.brandon3055.draconicevolution.common.lib.Strings;
import com.brandon3055.draconicevolution.common.tileentities.TilePlayerDetector;
public class PlayerDetector extends BlockDE {
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PlayerDetector extends BlockDE implements ITileEntityProvider {
@SideOnly(Side.CLIENT)
IIcon side_inactive;
@SideOnly(Side.CLIENT)
IIcon side_active;
@SideOnly(Side.CLIENT)
IIcon top;
@SideOnly(Side.CLIENT)
IIcon bottom;
public PlayerDetector() {
@@ -33,6 +41,7 @@ public class PlayerDetector extends BlockDE {
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
side_inactive = iconRegister.registerIcon(References.RESOURCESPREFIX + "player_detector_side_inactive");
side_active = iconRegister.registerIcon(References.RESOURCESPREFIX + "player_detector_side_active");
@@ -40,28 +49,39 @@ public class PlayerDetector extends BlockDE {
bottom = iconRegister.registerIcon(References.RESOURCESPREFIX + "machine_side");
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
if (side == 0) {
return bottom;
}
if (side == 1) {
return top;
}
IIcon side_icon;
TileEntity tile = world.getTileEntity(x, y, z);
if (tile != null && tile instanceof TilePlayerDetector && ((TilePlayerDetector) tile).output)
if (tile instanceof TilePlayerDetector detector && detector.shouldOutput()) {
side_icon = side_active;
else side_icon = side_inactive;
if (side == 0) return bottom;
else if (side == 1) return top;
else return side_icon;
} else {
side_icon = side_inactive;
}
return side_icon;
}
@Override
public IIcon getIcon(int side, int meta) {
if (side == 0) return bottom;
else if (side == 1) return top;
else return side_active;
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
if (side == 0) {
return bottom;
}
if (side == 1) {
return top;
}
return side_active;
}
@Override
public boolean isBlockSolid(IBlockAccess p_149747_1_, int p_149747_2_, int p_149747_3_, int p_149747_4_,
int p_149747_5_) {
public boolean isBlockSolid(IBlockAccess world, int x, int y, int z, int side) {
return true;
}
@@ -71,19 +91,18 @@ public class PlayerDetector extends BlockDE {
}
@Override
public boolean hasTileEntity(int meta) {
public boolean hasTileEntity(int metadata) {
return true;
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TilePlayerDetector();
}
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
if (side == 0 || side == 1) return false;
else return true;
return side >= 0;
}
@Override
@@ -92,27 +111,21 @@ public class PlayerDetector extends BlockDE {
}
@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
TilePlayerDetector detector = (te != null && te instanceof TilePlayerDetector) ? (TilePlayerDetector) te : null;
if (detector != null) return detector.output ? 15 : 0;
else return 0;
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
return isProvidingStrongPower(world, x, y, z, side);
}
@Override
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
TilePlayerDetector detector = (te != null && te instanceof TilePlayerDetector) ? (TilePlayerDetector) te : null;
if (detector != null) return detector.output ? 15 : 0;
else return 0;
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
TileEntity tile = world.getTileEntity(x, y, z);
return tile instanceof TilePlayerDetector detector && detector.shouldOutput() ? 15 : 0;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float p_149727_7_,
float p_149727_8_, float p_149727_9_) {
TileEntity te = world.getTileEntity(x, y, z);
TilePlayerDetector detector = (te != null && te instanceof TilePlayerDetector) ? (TilePlayerDetector) te : null;
if (detector != null) {
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TilePlayerDetector detector) {
int range = detector.getRange();
if (player.isSneaking()) {
@@ -121,25 +134,27 @@ public class PlayerDetector extends BlockDE {
range++;
}
if (range > 10) range = 1;
if (range < 1) range = 10;
detector.setRange(range);
if (world.isRemote) player.addChatMessage(
new ChatComponentTranslation("msg.range.txt").appendSibling(new ChatComponentText(" " + range)));
if (world.isRemote) {
player.addChatMessage(
new ChatComponentTranslation("msg.range.txt")
.appendSibling(new ChatComponentText(" " + detector.getRange())));
}
}
return true;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
super.breakBlock(world, x, y, z, block, meta);
world.notifyBlocksOfNeighborChange(x - 1, y, z, world.getBlock(x, y, z));
world.notifyBlocksOfNeighborChange(x + 1, y, z, world.getBlock(x, y, z));
world.notifyBlocksOfNeighborChange(x, y - 1, z, world.getBlock(x, y, z));
world.notifyBlocksOfNeighborChange(x, y + 1, z, world.getBlock(x, y, z));
world.notifyBlocksOfNeighborChange(x, y, z - 1, world.getBlock(x, y, z));
world.notifyBlocksOfNeighborChange(x, y, z + 1, world.getBlock(x, y, z));
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
super.breakBlock(world, x, y, z, blockBroken, metadata);
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
world.notifyBlocksOfNeighborChange(
x + direction.offsetX,
y + direction.offsetY,
z + direction.offsetZ,
blockBroken,
direction.getOpposite().ordinal());
}
}
}
@@ -28,9 +28,13 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PlayerDetectorAdvanced extends BlockCustomDrop {
@SideOnly(Side.CLIENT)
IIcon side_inactive;
@SideOnly(Side.CLIENT)
IIcon side_active;
@SideOnly(Side.CLIENT)
IIcon top;
@SideOnly(Side.CLIENT)
IIcon bottom;
public PlayerDetectorAdvanced() {
@@ -41,8 +45,8 @@ public class PlayerDetectorAdvanced extends BlockCustomDrop {
ModBlocks.register(this);
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
side_inactive = iconRegister
.registerIcon(References.RESOURCESPREFIX + "advanced_player_detector_side_inactive");
@@ -52,8 +56,7 @@ public class PlayerDetectorAdvanced extends BlockCustomDrop {
}
@Override
public boolean isBlockSolid(IBlockAccess p_149747_1_, int p_149747_2_, int p_149747_3_, int p_149747_4_,
int p_149747_5_) {
public boolean isBlockSolid(IBlockAccess world, int x, int y, int z, int side) {
return true;
}
@@ -62,47 +65,50 @@ public class PlayerDetectorAdvanced extends BlockCustomDrop {
return true;
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
IIcon side_icon;
TileEntity tile = world.getTileEntity(x, y, z);
TilePlayerDetectorAdvanced detector = (tile != null && tile instanceof TilePlayerDetectorAdvanced)
? (TilePlayerDetectorAdvanced) tile
: null;
if (detector != null && detector.getStackInSlot(0) != null) {
ItemStack stack = detector.getStackInSlot(0);
Block block = Block.getBlockFromItem(stack.getItem());
if (block != null && block.renderAsNormalBlock()) return block.getIcon(side, stack.getItemDamage());
} else {
if (detector != null && detector.output) side_icon = side_active;
else side_icon = side_inactive;
if (side == 0) return bottom;
else if (side == 1) return top;
else return side_icon;
if (tile instanceof TilePlayerDetectorAdvanced detector) {
if (detector.getStackInSlot(0) != null) {
ItemStack stack = detector.getStackInSlot(0);
Block block = Block.getBlockFromItem(stack.getItem());
if (block != null && block.renderAsNormalBlock()) {
return block.getIcon(side, stack.getItemDamage());
}
} else {
if (side == 0) {
return bottom;
}
if (side == 1) {
return top;
}
return detector.shouldOutput() ? side_active : side_inactive;
}
}
return null;
return side_active;
}
@Override
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
if (side == 0) return bottom;
else if (side == 1) return top;
else return side_active;
public IIcon getIcon(int side, int metadata) {
if (side == 0) {
return bottom;
}
if (side == 1) {
return top;
}
return side_active;
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TilePlayerDetectorAdvanced();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
if (!world.isRemote) {
FMLNetworkHandler
.openGui(player, DraconicEvolution.instance, GuiHandler.GUIID_PLAYERDETECTOR, world, x, y, z);
@@ -112,8 +118,7 @@ public class PlayerDetectorAdvanced extends BlockCustomDrop {
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
if (side == 0 || side == 1) return false;
else return true;
return side >= 0;
}
@Override
@@ -122,25 +127,14 @@ public class PlayerDetectorAdvanced extends BlockCustomDrop {
}
@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
TilePlayerDetectorAdvanced detector = (te != null && te instanceof TilePlayerDetectorAdvanced)
? (TilePlayerDetectorAdvanced) te
: null;
if (detector != null) if (!detector.outputInverted) return detector.output ? 15 : 0;
else return detector.output ? 0 : 15;
else return 0;
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
return isProvidingStrongPower(world, x, y, z, side);
}
@Override
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
TilePlayerDetectorAdvanced detector = (te != null && te instanceof TilePlayerDetectorAdvanced)
? (TilePlayerDetectorAdvanced) te
: null;
if (detector != null) if (!detector.outputInverted) return detector.output ? 15 : 0;
else return detector.output ? 0 : 15;
else return 0;
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
TileEntity tile = world.getTileEntity(x, y, z);
return tile instanceof TilePlayerDetectorAdvanced detector && detector.shouldOutput() ? 15 : 0;
}
@Override
@@ -154,17 +148,30 @@ public class PlayerDetectorAdvanced extends BlockCustomDrop {
}
@Override
protected void getCustomTileEntityDrops(TileEntity te, List<ItemStack> droppes) {}
protected void getCustomTileEntityDrops(TileEntity tile, List<ItemStack> drops) {}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
TilePlayerDetectorAdvanced detector = (te != null && te instanceof TilePlayerDetectorAdvanced)
? (TilePlayerDetectorAdvanced) te
: null;
if (detector != null && detector.getStackInSlot(0) != null) {
return detector.getStackInSlot(0);
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TilePlayerDetectorAdvanced detector) {
ItemStack stackInSlot = detector.getStackInSlot(0);
if (stackInSlot != null) {
return stackInSlot;
}
}
return super.getPickBlock(target, world, x, y, z, player);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
super.breakBlock(world, x, y, z, blockBroken, metadata);
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
world.notifyBlocksOfNeighborChange(
x + direction.offsetX,
y + direction.offsetY,
z + direction.offsetZ,
blockBroken,
direction.getOpposite().ordinal());
}
return super.getPickBlock(target, world, x, y, z);
}
}
@@ -22,11 +22,15 @@ import com.brandon3055.draconicevolution.common.items.tools.TeleporterMKI;
import com.brandon3055.draconicevolution.common.lib.References;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.TileDislocatorReceptacle;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 19/5/2015.
*/
public class DislocatorReceptacle extends BlockCustomDrop implements ITileEntityProvider {
@SideOnly(Side.CLIENT)
IIcon textureInactive;
public DislocatorReceptacle() {
@@ -41,6 +45,7 @@ public class DislocatorReceptacle extends BlockCustomDrop implements ITileEntity
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
textureInactive = iconRegister
.registerIcon(References.RESOURCESPREFIX + "animated/dislocatorReceptacle_inactive");
@@ -48,23 +53,21 @@ public class DislocatorReceptacle extends BlockCustomDrop implements ITileEntity
}
@Override
public IIcon getIcon(IBlockAccess access, int x, int y, int z, int side) {
TileDislocatorReceptacle tile = access.getTileEntity(x, y, z) instanceof TileDislocatorReceptacle
? (TileDislocatorReceptacle) access.getTileEntity(x, y, z)
: null;
if (tile != null) return tile.isActive ? blockIcon : textureInactive;
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileDislocatorReceptacle receptacle) {
return receptacle.isActive ? blockIcon : textureInactive;
}
return blockIcon;
}
@Override
public void updateTick(World world, int x, int y, int z, Random random) {
TileDislocatorReceptacle tile = (TileDislocatorReceptacle) world.getTileEntity(x, y, z);
if (tile != null) tile.updateState();
}
@Override
public IIcon getIcon(int p_149691_1_, int meta) {
return blockIcon;
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileDislocatorReceptacle receptacle) {
receptacle.updateState();
}
}
@Override
@@ -72,44 +75,44 @@ public class DislocatorReceptacle extends BlockCustomDrop implements ITileEntity
return true;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileDislocatorReceptacle();
}
@Override
public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) {
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileDislocatorReceptacle();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float p_149727_7_,
float p_149727_8_, float p_149727_9_) {
if (world.isRemote) return true;
TileDislocatorReceptacle tile = (TileDislocatorReceptacle) world.getTileEntity(x, y, z);
if (tile == null) return false;
if (tile.getStackInSlot(0) != null) {
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
if (world.isRemote) {
return true;
}
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileDislocatorReceptacle receptacle)) {
return false;
}
ItemStack stackInSlot = receptacle.getStackInSlot(0);
if (stackInSlot != null) {
if (player.getHeldItem() == null) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, tile.getStackInSlot(0));
tile.setInventorySlotContents(0, null);
player.inventory.setInventorySlotContents(player.inventory.currentItem, stackInSlot);
} else {
world.spawnEntityInWorld(
new EntityItem(world, player.posX, player.posY, player.posZ, tile.getStackInSlot(0)));
tile.setInventorySlotContents(0, null);
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, stackInSlot));
}
receptacle.setInventorySlotContents(0, null);
world.markBlockForUpdate(x, y, z);
world.notifyBlockChange(x, y, z, this);
} else {
ItemStack stack = player.getHeldItem();
if (stack != null && stack.getItem() instanceof TeleporterMKI
&& ((TeleporterMKI) stack.getItem()).getLocation(stack) != null) {
tile.setInventorySlotContents(0, player.getHeldItem());
if (stack != null && stack.getItem() instanceof TeleporterMKI teleporter
&& teleporter.getLocation(stack) != null) {
receptacle.setInventorySlotContents(0, player.getHeldItem());
player.destroyCurrentEquippedItem();
}
}
return true;
}
@@ -120,8 +123,13 @@ public class DislocatorReceptacle extends BlockCustomDrop implements ITileEntity
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int p_149736_5_) {
TileDislocatorReceptacle tile = (TileDislocatorReceptacle) world.getTileEntity(x, y, z);
return tile == null ? 0 : tile.getStackInSlot(0) != null ? 15 : 0;
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileDislocatorReceptacle receptacle) {
if (receptacle.getStackInSlot(0) != null) {
return 15;
}
}
return 0;
}
@Override
@@ -135,5 +143,5 @@ public class DislocatorReceptacle extends BlockCustomDrop implements ITileEntity
}
@Override
protected void getCustomTileEntityDrops(TileEntity te, List<ItemStack> droppes) {}
protected void getCustomTileEntityDrops(TileEntity tile, List<ItemStack> drops) {}
}
@@ -1,6 +1,7 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@@ -23,12 +24,13 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 28/07/2014.
*/
public class EnergyPylon extends BlockDE { // todo fix sphere renderer
public class EnergyPylon extends BlockDE implements ITileEntityProvider {
@SideOnly(Side.CLIENT)
public IIcon icon_active_face;
@SideOnly(Side.CLIENT)
public IIcon icon_input;
@SideOnly(Side.CLIENT)
public IIcon icon_output;
public EnergyPylon() {
@@ -46,9 +48,8 @@ public class EnergyPylon extends BlockDE { // todo fix sphere renderer
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
if (metadata == 1 || metadata == 2) return new TileEnergyPylon();
else return null;
public TileEntity createNewTileEntity(World world, int metadata) {
return metadata == 1 || metadata == 2 ? new TileEnergyPylon() : null;
}
@Override
@@ -61,109 +62,80 @@ public class EnergyPylon extends BlockDE { // todo fix sphere renderer
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {
if (meta == 1 && side == 1) return icon_active_face;
if (meta == 2 && side == 0) return icon_active_face;
return icon_input;
public IIcon getIcon(int side, int metadata) {
return metadata == 1 && side == 1 || metadata == 2 && side == 0 ? icon_active_face : icon_input;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 1 && side == 1) return icon_active_face;
if (meta == 2 && side == 0) return icon_active_face;
TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y, z)
: null;
if (thisTile == null) return icon_input;
return !thisTile.reciveEnergy ? icon_output : icon_input;
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 1 && side == 1 || metadata == 2 && side == 0) return icon_active_face;
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEnergyPylon pylon) {
return pylon.isReceivingEnergy ? icon_input : icon_output;
}
return icon_input;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0) {
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
updateBlockState(world, x, y, z);
}
private void updateBlockState(World world, int x, int y, int z) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 0) {
if (world.getBlock(x, y + 1, z) == Blocks.glass) {
world.setBlockMetadataWithNotify(x, y, z, 1, 2);
metadata = 1;
world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
world.setBlock(x, y + 1, z, ModBlocks.invisibleMultiblock, 2, 2);
} else if (world.getBlock(x, y - 1, z) == Blocks.glass) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
metadata = 2;
world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
world.setBlock(x, y - 1, z, ModBlocks.invisibleMultiblock, 2, 2);
}
} else {
TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y, z)
: null;
if (thisTile == null || (meta == 1 && !isGlass(world, x, y + 1, z))
|| (meta == 2 && !isGlass(world, x, y - 1, z))) {
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileEnergyPylon) || (metadata == 1 && isGlassMissing(world, x, y + 1, z))
|| (metadata == 2 && isGlassMissing(world, x, y - 1, z))) {
metadata = 0;
world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
}
}
TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y, z)
: null;
if (thisTile != null) {
thisTile.onActivated();
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEnergyPylon) {
((TileEnergyPylon) tile).onActivated();
if (metadata == 0) {
world.removeTileEntity(x, y, z);
}
}
if (world.getBlockMetadata(x, y, z) == 0 && world.getTileEntity(x, y, z) != null)
world.removeTileEntity(x, y, z);
}
private boolean isGlass(World world, int x, int y, int z) {
return world.getBlock(x, y, z) == ModBlocks.invisibleMultiblock && world.getBlockMetadata(x, y, z) == 2;
private boolean isGlassMissing(World world, int x, int y, int z) {
return world.getBlock(x, y, z) != ModBlocks.invisibleMultiblock || world.getBlockMetadata(x, y, z) != 2;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0) return false;
TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y, z)
: null;
if (thisTile != null) {
if (!player.isSneaking()) thisTile.onActivated();
else thisTile.nextCore();
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 0) return false;
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEnergyPylon pylon) {
if (player.isSneaking()) {
pylon.nextCore();
} else {
pylon.onActivated();
}
return true;
}
return false;
}
@Override
public void onPostBlockPlaced(World world, int x, int y, int z, int p_149714_5_) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0) {
if (world.getBlock(x, y + 1, z) == Blocks.glass) {
world.setBlockMetadataWithNotify(x, y, z, 1, 2);
world.setBlock(x, y + 1, z, ModBlocks.invisibleMultiblock, 2, 2);
} else if (world.getBlock(x, y - 1, z) == Blocks.glass) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
world.setBlock(x, y - 1, z, ModBlocks.invisibleMultiblock, 2, 2);
}
} else {
TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y, z)
: null;
if (thisTile == null || (meta == 1 && !isGlass(world, x, y + 1, z))
|| (meta == 2 && !isGlass(world, x, y - 1, z))) {
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
}
}
TileEnergyPylon thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y, z)
: null;
if (thisTile != null) {
thisTile.onActivated();
}
if (world.getBlockMetadata(x, y, z) == 0 && world.getTileEntity(x, y, z) != null)
world.removeTileEntity(x, y, z);
public void onPostBlockPlaced(World world, int x, int y, int z, int metadata) {
updateBlockState(world, x, y, z);
}
@Override
@@ -172,11 +144,11 @@ public class EnergyPylon extends BlockDE { // todo fix sphere renderer
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int meta) {
TileEnergyPylon tile = world.getTileEntity(x, y, z) instanceof TileEnergyPylon
? (TileEnergyPylon) world.getTileEntity(x, y, z)
: null;
if (tile != null) return (int) (tile.getEnergyStored() / tile.getMaxEnergyStored() * 15D);
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEnergyPylon pylon) {
return (int) (pylon.getEnergyStored() / pylon.getMaxEnergyStored() * 15D);
}
return 0;
}
}
@@ -1,22 +1,20 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.StatCollector;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.brandonscore.common.utills.InfoHelper;
import com.brandon3055.brandonscore.common.utills.Utills;
import com.brandon3055.draconicevolution.DraconicEvolution;
import com.brandon3055.draconicevolution.common.ModBlocks;
import com.brandon3055.draconicevolution.common.blocks.BlockDE;
@@ -32,7 +30,7 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 25/07/2014.
*/
public class EnergyStorageCore extends BlockDE implements IHudDisplayBlock {
public class EnergyStorageCore extends BlockDE implements IHudDisplayBlock, ITileEntityProvider {
public EnergyStorageCore() {
super(Material.iron);
@@ -65,34 +63,23 @@ public class EnergyStorageCore extends BlockDE implements IHudDisplayBlock {
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileEnergyStorageCore();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
TileEnergyStorageCore tile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(x, y, z)
: null;
if (tile == null) {
LogHelper.error("Missing Tile Entity (EnergyStorageCore)");
return false;
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
if (!world.isRemote) {
player.addChatComponentMessage(new ChatComponentText("Tier:" + (tile.getTier() + 1)));
String BN = String.valueOf(tile.getEnergyStored());
player.addChatComponentMessage(
new ChatComponentText(
StatCollector.translateToLocal("info.de.charge.txt") + ": "
+ Utills.formatNumber(tile.getEnergyStored())
+ " / "
+ Utills.formatNumber(tile.getMaxEnergyStored())
+ " ["
+ BN
+ " RF]"));
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileEnergyStorageCore core)) {
LogHelper.error("Missing Tile Entity (EnergyStorageCore)");
return false;
}
List<String> information = core.getDisplayInformation(false);
for (String message : information) {
player.addChatComponentMessage(new ChatComponentText(message));
}
}
return true;
}
@@ -100,96 +87,60 @@ public class EnergyStorageCore extends BlockDE implements IHudDisplayBlock {
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) {
TileEnergyStorageCore tile = (world.getTileEntity(
x - ForgeDirection.getOrientation(side).offsetX,
y - ForgeDirection.getOrientation(side).offsetY,
z - ForgeDirection.getOrientation(side).offsetZ) != null
&& world.getTileEntity(
x - ForgeDirection.getOrientation(side).offsetX,
y - ForgeDirection.getOrientation(side).offsetY,
z - ForgeDirection.getOrientation(side).offsetZ) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(
x - ForgeDirection.getOrientation(side).offsetX,
y - ForgeDirection.getOrientation(side).offsetY,
z - ForgeDirection.getOrientation(side).offsetZ)
: null;
// LogHelper.error(world.getTileEntity(x - ForgeDirection.getOrientation(side).offsetX, y -
// ForgeDirection.getOrientation(side).offsetY, z - ForgeDirection.getOrientation(side).offsetZ));
if (tile == null) {
ForgeDirection direction = ForgeDirection.getOrientation(side);
TileEntity tile = world.getTileEntity(x - direction.offsetX, y - direction.offsetY, z - direction.offsetZ);
if (!(tile instanceof TileEnergyStorageCore core)) {
LogHelper.error("Missing Tile Entity (EnergyStorageCore)(shouldSideBeRendered)");
return true;
}
if (tile.isOnline()) return false;
else return super.shouldSideBeRendered(world, x, y, z, side);
return !core.isOnline() && super.shouldSideBeRendered(world, x, y, z, side);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) {
TileEnergyStorageCore thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(x, y, z)
: null;
if (thisTile != null && thisTile.isOnline() && thisTile.getTier() == 0) {
thisTile.isStructureStillValid(false);
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEnergyStorageCore core) {
if (core.isOnline() && core.getTier() == 0) {
core.validateStructure(false);
}
}
}
@Override
public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int p_149749_6_) {
TileEnergyStorageCore thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(x, y, z)
: null;
if (thisTile != null && thisTile.isOnline() && thisTile.getTier() == 0) {
thisTile.deactivateStabilizers();
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEnergyStorageCore core) {
if (core.isOnline() && core.getTier() == 0) {
core.deactivateStabilizers();
}
}
super.breakBlock(world, x, y, z, p_149749_5_, p_149749_6_);
super.breakBlock(world, x, y, z, blockBroken, metadata);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
TileEnergyStorageCore thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(x, y, z)
: null;
if (thisTile != null && thisTile.isOnline()) {
return AxisAlignedBB.getBoundingBox(
thisTile.xCoord + 0.5,
thisTile.yCoord + 0.5,
thisTile.zCoord + 0.5,
thisTile.xCoord + 0.5,
thisTile.yCoord + 0.5,
thisTile.zCoord + 0.5);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEnergyStorageCore core) {
if (core.isOnline()) {
return AxisAlignedBB.getBoundingBox(
core.xCoord + 0.5,
core.yCoord + 0.5,
core.zCoord + 0.5,
core.xCoord + 0.5,
core.yCoord + 0.5,
core.zCoord + 0.5);
}
}
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
}
@Override
public List<String> getDisplayData(World world, int x, int y, int z) {
List<String> list = new ArrayList<String>();
TileEnergyStorageCore tile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) world.getTileEntity(x, y, z)
: null;
if (tile == null) {
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileEnergyStorageCore core)) {
LogHelper.error("Missing Tile Entity (EnergyStorageCore getDisplayData)");
return list;
return Collections.emptyList();
}
list.add(InfoHelper.HITC() + getLocalizedName());
list.add("Tier: " + InfoHelper.ITC() + (tile.getTier() + 1));
String BN = String.valueOf(tile.getEnergyStored());
list.add(
StatCollector.translateToLocal("info.de.charge.txt") + ": "
+ InfoHelper.ITC()
+ Utills.formatNumber(tile.getEnergyStored())
+ " / "
+ Utills.formatNumber(tile.getMaxEnergyStored())
+ " ["
+ BN
+ " RF]");
return list;
return core.getDisplayInformation(true);
}
}
@@ -1,30 +1,68 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore;
/**
* Created by Brandon on 23/7/2015.
*/
public interface IReactorPart {
public static int RMODE_TEMP = 0;
public static int RMODE_TEMP_INV = 1;
public static int RMODE_FIELD = 2;
public static int RMODE_FIELD_INV = 3;
public static int RMODE_SAT = 4;
public static int RMODE_SAT_INV = 5;
public static int RMODE_FUEL = 6;
public static int RMODE_FUEL_INV = 7;
enum ComparatorMode {
public MultiblockHelper.TileLocation getMaster();
TEMPERATURE,
TEMPERATURE_INVERTED,
FIELD_CHARGE,
FIELD_CHARGE_INVERTED,
ENERGY_SATURATION,
ENERGY_SATURATION_INVERTED,
CONVERTED_FUEL,
CONVERTED_FUEL_INVERTED;
public void shutDown();
private static final ComparatorMode[] values = values();
public boolean checkForMaster();
public static ComparatorMode getMode(int ordinal) {
return ordinal >= 0 && ordinal < values.length ? values[ordinal] : TEMPERATURE;
}
public boolean isActive();
public ComparatorMode next() {
return values[(ordinal() + 1) % values.length];
}
public String getRedstoneModeString();
public String toLocalizedString() {
return StatCollector.translateToLocal("msg.de.reactorRSMode." + ordinal() + ".txt");
}
}
public void changeRedstoneMode();
static int getComparatorOutput(IBlockAccess world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof IReactorPart part) {
TileReactorCore core = part.getMaster();
if (core != null) {
return core.getComparatorOutput(part.getComparatorMode());
}
}
return 0;
}
public int getRedstoneMode();
TileLocation getMasterLocation();
TileReactorCore getMaster();
void setUp(TileLocation masterLocation);
void shutDown();
boolean isActive();
ForgeDirection getFacing();
ComparatorMode getComparatorMode();
void changeComparatorMode();
}
@@ -1,10 +1,11 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@@ -15,11 +16,8 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import com.brandon3055.brandonscore.common.utills.InfoHelper;
import com.brandon3055.brandonscore.common.utills.Utills;
import com.brandon3055.draconicevolution.common.ModBlocks;
import com.brandon3055.draconicevolution.common.blocks.BlockDE;
import com.brandon3055.draconicevolution.common.handler.BalanceConfigHandler;
@@ -37,13 +35,33 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 25/07/2014.
*/
public class InvisibleMultiblock extends BlockDE implements IHudDisplayBlock {
public class InvisibleMultiblock extends BlockDE implements IHudDisplayBlock, ITileEntityProvider {
public static void revertStructure(World world, int x, int y, int z) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 0) {
world.setBlock(
x,
y,
z,
BalanceConfigHandler.energyStorageStructureOuterBlock,
BalanceConfigHandler.energyStorageStructureOuterBlockMetadata,
3);
} else if (metadata == 1) {
world.setBlock(
x,
y,
z,
BalanceConfigHandler.energyStorageStructureBlock,
BalanceConfigHandler.energyStorageStructureBlockMetadata,
3);
}
}
public InvisibleMultiblock() {
super(Material.iron);
this.setHardness(10F);
this.setResistance(2000F);
// this.setCreativeTab(DraconicEvolution.getCreativeTab(2));
this.setBlockName(Strings.invisibleMultiblockName);
ModBlocks.register(this);
}
@@ -76,17 +94,16 @@ public class InvisibleMultiblock extends BlockDE implements IHudDisplayBlock {
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
if (metadata == 0 || metadata == 1) return new TileInvisibleMultiblock();
else return null;
public TileEntity createNewTileEntity(World world, int metadata) {
return metadata == 0 || metadata == 1 ? new TileInvisibleMultiblock() : null;
}
@Override
public Item getItemDropped(int meta, Random p_149650_2_, int var2) {
if (meta == 0) {
public Item getItemDropped(int metadata, Random random, int fortune) {
if (metadata == 0) {
return Item.getItemFromBlock(BalanceConfigHandler.energyStorageStructureOuterBlock);
}
if (meta == 1) {
if (metadata == 1) {
return Item.getItemFromBlock(BalanceConfigHandler.energyStorageStructureBlock);
}
return null;
@@ -104,48 +121,37 @@ public class InvisibleMultiblock extends BlockDE implements IHudDisplayBlock {
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0 || meta == 1) {
TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock)
? (TileInvisibleMultiblock) world.getTileEntity(x, y, z)
: null;
if (thisTile == null) {
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 0 || metadata == 1) {
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileInvisibleMultiblock multiblock)) {
LogHelper.error("Missing Tile Entity (TileInvisibleMultiblock)");
return false;
}
TileEnergyStorageCore master = thisTile.getMaster();
if (master == null) {
TileEnergyStorageCore core = multiblock.getMaster();
if (core == null) {
onNeighborBlockChange(world, x, y, z, this);
return false;
}
if (!world.isRemote) {
world.markBlockForUpdate(master.xCoord, master.yCoord, master.zCoord);
player.addChatComponentMessage(new ChatComponentText("Tier:" + (master.getTier() + 1)));
String BN = String.valueOf(master.getEnergyStored());
player.addChatComponentMessage(
new ChatComponentText(
StatCollector.translateToLocal("info.de.charge.txt") + ": "
+ Utills.formatNumber(master.getEnergyStored())
+ " / "
+ Utills.formatNumber(master.getMaxEnergyStored())
+ " ["
+ BN
+ " RF]"));
world.markBlockForUpdate(core.xCoord, core.yCoord, core.zCoord);
List<String> information = core.getDisplayInformation(false);
for (String message : information) {
player.addChatComponentMessage(new ChatComponentText(message));
}
}
return true;
} else if (meta == 2) {
TileEnergyPylon pylon = (world.getTileEntity(x, y + 1, z) != null
&& world.getTileEntity(x, y + 1, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y + 1, z)
: (world.getTileEntity(x, y - 1, z) != null
&& world.getTileEntity(x, y - 1, z) instanceof TileEnergyPylon)
? (TileEnergyPylon) world.getTileEntity(x, y - 1, z)
: null;
if (pylon == null) return false;
pylon.reciveEnergy = !pylon.reciveEnergy;
} else if (metadata == 2) {
TileEntity tileAbove = world.getTileEntity(x, y + 1, z);
TileEntity tileBelow = world.getTileEntity(x, y - 1, z);
TileEnergyPylon pylon = tileAbove instanceof TileEnergyPylon ? (TileEnergyPylon) tileAbove
: tileBelow instanceof TileEnergyPylon ? (TileEnergyPylon) tileBelow : null;
if (pylon == null) {
return false;
}
pylon.isReceivingEnergy = !pylon.isReceivingEnergy;
world.markBlockForUpdate(pylon.xCoord, pylon.yCoord, pylon.zCoord);
pylon.onActivated();
return true;
@@ -154,87 +160,65 @@ public class InvisibleMultiblock extends BlockDE implements IHudDisplayBlock {
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block p_149695_5_) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0 || meta == 1) {
TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock)
? (TileInvisibleMultiblock) world.getTileEntity(x, y, z)
: null;
if (thisTile == null) {
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 0 || metadata == 1) {
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileInvisibleMultiblock multiblock)) {
LogHelper.error("Missing Tile Entity (TileInvisibleMultiblock)");
revert(world, x, y, z);
revertStructure(world, x, y, z);
return;
}
TileEnergyStorageCore master = thisTile.getMaster();
if (master == null) {
TileEnergyStorageCore core = multiblock.getMaster();
if (core == null) {
LogHelper.error("Master = null reverting!");
revert(world, x, y, z);
revertStructure(world, x, y, z);
return;
}
if (master.isOnline()) master.isStructureStillValid(thisTile.getMaster().getTier() == 1);
if (!master.isOnline()) revert(world, x, y, z);
} else if (meta == 2) {
if (core.isOnline()) {
core.validateStructure(core.getTier() == 1);
} else {
revertStructure(world, x, y, z);
}
} else if (metadata == 2) {
if (world.getBlock(x, y + 1, z) != ModBlocks.energyPylon
&& world.getBlock(x, y - 1, z) != ModBlocks.energyPylon)
world.setBlock(x, y, z, Blocks.glass);
}
}
private void revert(World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0) {
world.setBlock(
x,
y,
z,
BalanceConfigHandler.energyStorageStructureOuterBlock,
BalanceConfigHandler.energyStorageStructureOuterBlockMetadata,
3);
} else if (meta == 1) {
world.setBlock(
x,
y,
z,
BalanceConfigHandler.energyStorageStructureBlock,
BalanceConfigHandler.energyStorageStructureBlockMetadata,
3);
}
}
@Override
public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int meta) {
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
TileEntity tile = world.getTileEntity(x, y, z);
TileInvisibleMultiblock thisTile = (tile != null && tile instanceof TileInvisibleMultiblock)
? (TileInvisibleMultiblock) tile
: null;
if (thisTile != null && thisTile.getMaster() != null && thisTile.getMaster().isOnline()) {
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
thisTile.getMaster().isStructureStillValid(thisTile.getMaster().getTier() == 1);
if (tile instanceof TileInvisibleMultiblock multiblock) {
TileEnergyStorageCore core = multiblock.getMaster();
if (core != null && core.isOnline()) {
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
core.validateStructure(core.getTier() == 1);
}
}
super.breakBlock(world, x, y, z, p_149749_5_, meta);
super.breakBlock(world, x, y, z, blockBroken, metadata);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0 || meta == 1) {
TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock)
? (TileInvisibleMultiblock) world.getTileEntity(x, y, z)
: null;
if (thisTile != null && thisTile.getMaster() != null) {
return AxisAlignedBB.getBoundingBox(
thisTile.getMaster().xCoord,
thisTile.getMaster().yCoord,
thisTile.getMaster().zCoord,
thisTile.getMaster().xCoord + 0.5,
thisTile.getMaster().yCoord + 0.5,
thisTile.getMaster().zCoord + 0.5);
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 0 || metadata == 1) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileInvisibleMultiblock multiblock) {
TileEnergyStorageCore core = multiblock.getMaster();
if (core != null) {
return AxisAlignedBB.getBoundingBox(
core.xCoord,
core.yCoord,
core.zCoord,
core.xCoord + 0.5,
core.yCoord + 0.5,
core.zCoord + 0.5);
}
}
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
} else if (meta == 2) {
} else if (metadata == 2) {
return AxisAlignedBB.getBoundingBox(x + 0.49, y + 0.49, z + 0.49, x + 0.51, y + 0.51, z + 0.51);
}
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
@@ -242,9 +226,8 @@ public class InvisibleMultiblock extends BlockDE implements IHudDisplayBlock {
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 2) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 2) {
return AxisAlignedBB.getBoundingBox(x, y, z, x, y, z);
}
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
@@ -270,46 +253,18 @@ public class InvisibleMultiblock extends BlockDE implements IHudDisplayBlock {
@Override
public List<String> getDisplayData(World world, int x, int y, int z) {
List<String> list = new ArrayList<String>();
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0 || meta == 1) {
TileInvisibleMultiblock thisTile = (world.getTileEntity(x, y, z) != null
&& world.getTileEntity(x, y, z) instanceof TileInvisibleMultiblock)
? (TileInvisibleMultiblock) world.getTileEntity(x, y, z)
: null;
if (thisTile == null) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 0 || metadata == 1) {
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileInvisibleMultiblock multiblock)) {
LogHelper.error("Missing Tile Entity (TileInvisibleMultiblock getDisplayData)");
return list;
return Collections.emptyList();
}
TileEnergyStorageCore master = thisTile.getMaster();
if (master == null) {
return list;
TileEnergyStorageCore core = multiblock.getMaster();
if (core != null) {
return core.getDisplayInformation(true);
}
list.add(InfoHelper.HITC() + ModBlocks.energyStorageCore.getLocalizedName());
list.add("Tier: " + InfoHelper.ITC() + (master.getTier() + 1));
String BN = String.valueOf(master.getEnergyStored());
list.add(
StatCollector.translateToLocal("info.de.charge.txt") + ": "
+ InfoHelper.ITC()
+ Utills.formatNumber(master.getEnergyStored())
+ " / "
+ Utills.formatNumber(master.getMaxEnergyStored())
+ " ["
+ Utills.addCommas(master.getEnergyStored())
+ " RF]");
return list;
}
return list;
}
@Override
public String getUnlocalizedName() {
return super.getUnlocalizedName();
return Collections.emptyList();
}
}
@@ -1,5 +1,6 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
@@ -60,6 +61,14 @@ public class MultiblockHelper {
initialized = true;
}
public Block getBlock(World world) {
return world.getBlock(posX, posY, posZ);
}
public int getBlockMetadata(World world) {
return world.getBlockMetadata(posX, posY, posZ);
}
public TileEntity getTileEntity(World world) {
return world.getTileEntity(posX, posY, posZ);
}
@@ -35,8 +35,8 @@ public class Portal extends BlockDE implements ITileEntityProvider {
ModBlocks.register(this);
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "transparency");
}
@@ -47,8 +47,7 @@ public class Portal extends BlockDE implements ITileEntityProvider {
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World p_149633_1_, int p_149633_2_, int p_149633_3_,
int p_149633_4_) {
public AxisAlignedBB getSelectedBoundingBoxFromPool(World worldIn, int x, int y, int z) {
return AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
}
@@ -63,26 +62,35 @@ public class Portal extends BlockDE implements ITileEntityProvider {
}
@Override
public TileEntity createNewTileEntity(World world, int i) {
public boolean hasTileEntity(int metadata) {
return true;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TilePortalBlock();
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_,
int p_149668_4_) {
public AxisAlignedBB getCollisionBoundingBoxFromPool(World worldIn, int x, int y, int z) {
return null;
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
if (world.isRemote) return;
if (getMaster(world, x, y, z) == null) {
if (world.isRemote) {
return;
}
TileDislocatorReceptacle receptacle = getMaster(world, x, y, z);
if (receptacle == null) {
world.setBlockToAir(x, y, z);
return;
}
if (getMaster(world, x, y, z).isActive) getMaster(world, x, y, z).validateActivePortal();
if (!getMaster(world, x, y, z).isActive && !getMaster(world, x, y, z).updating) {
if (receptacle.isActive) {
receptacle.validateActivePortal();
}
if (!receptacle.isActive && !receptacle.updating) {
world.setBlockToAir(x, y, z);
return;
}
@@ -91,29 +99,37 @@ public class Portal extends BlockDE implements ITileEntityProvider {
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if (world.isRemote) return;
TileDislocatorReceptacle tile = getMaster(world, x, y, z);
if (tile != null && tile.isActive && tile.getLocation() != null) {
if (tile.coolDown > 0) return;
tile.coolDown = 1;
tile.getLocation().sendEntityToCoords(entity);
} else if (tile != null) tile.validateActivePortal();
else world.setBlockToAir(x, y, z);
if (world.isRemote) {
return;
}
TileDislocatorReceptacle receptacle = getMaster(world, x, y, z);
if (receptacle == null) {
world.setBlockToAir(x, y, z);
return;
}
if (receptacle.isActive && receptacle.getLocation() != null) {
if (receptacle.coolDown > 0) {
return;
}
receptacle.coolDown = 1;
receptacle.getLocation().sendEntityToCoords(entity);
} else {
receptacle.validateActivePortal();
}
}
private TileDislocatorReceptacle getMaster(World world, int x, int y, int z) {
return world.getTileEntity(x, y, z) instanceof TilePortalBlock
? ((TilePortalBlock) world.getTileEntity(x, y, z)).getMaster()
: null;
TileEntity tile = world.getTileEntity(x, y, z);
return tile instanceof TilePortalBlock portal ? portal.getMaster() : null;
}
@Override
public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) {
public Item getItemDropped(int metadata, Random random, int fortune) {
return null;
}
private boolean isPortalOrFrame(IBlockAccess access, int x, int y, int z) {
Block block = access.getBlock(x, y, z);
private boolean isPortalOrFrame(IBlockAccess world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == ModBlocks.portal || block == ModBlocks.infusedObsidian
|| block == ModBlocks.dislocatorReceptacle;
}
@@ -124,22 +140,21 @@ public class Portal extends BlockDE implements ITileEntityProvider {
}
private void updateMetadata(World world, int x, int y, int z) {
if (world.isRemote || world.getBlockMetadata(x, y, z) != 0) return;
int meta = 0;
if (world.isRemote || world.getBlockMetadata(x, y, z) != 0) {
return;
}
int metadata = 0;
boolean hasPortalsAlongXAxis = isPortalOrFrame(world, x + 1, y, z) && isPortalOrFrame(world, x - 1, y, z);
boolean hasPortalsAlongYAxis = isPortalOrFrame(world, x, y + 1, z) && isPortalOrFrame(world, x, y - 1, z);
boolean hasPortalsAlongZAxis = isPortalOrFrame(world, x, y, z + 1) && isPortalOrFrame(world, x, y, z - 1);
if (isPortalOrFrame(world, x, y + 1, z) && isPortalOrFrame(world, x, y - 1, z)
&& isPortalOrFrame(world, x + 1, y, z)
&& isPortalOrFrame(world, x - 1, y, z))
meta = 1;
else if (isPortalOrFrame(world, x, y + 1, z) && isPortalOrFrame(world, x, y - 1, z)
&& isPortalOrFrame(world, x, y, z + 1)
&& isPortalOrFrame(world, x, y, z - 1))
meta = 2;
else if (isPortalOrFrame(world, x + 1, y, z) && isPortalOrFrame(world, x - 1, y, z)
&& isPortalOrFrame(world, x, y, z + 1)
&& isPortalOrFrame(world, x, y, z - 1))
meta = 3;
world.setBlockMetadataWithNotify(x, y, z, meta, 2);
if (hasPortalsAlongXAxis && hasPortalsAlongYAxis) {
metadata = 1;
} else if (hasPortalsAlongYAxis && hasPortalsAlongZAxis) {
metadata = 2;
} else if (hasPortalsAlongXAxis && hasPortalsAlongZAxis) {
metadata = 3;
}
world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
}
}
@@ -1,8 +1,8 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
@@ -19,7 +19,7 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 16/6/2015.
*/
public class ReactorCore extends BlockDE {
public class ReactorCore extends BlockDE implements ITileEntityProvider {
public ReactorCore() {
this.setCreativeTab(DraconicEvolution.tabBlocksItems);
@@ -29,8 +29,8 @@ public class ReactorCore extends BlockDE {
ModBlocks.register(this);
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "transparency");
}
@@ -56,40 +56,29 @@ public class ReactorCore extends BlockDE {
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileReactorCore();
}
@Override
public void onBlockAdded(World world, int x, int y, int z) {
TileReactorCore tile = world.getTileEntity(x, y, z) instanceof TileReactorCore
? (TileReactorCore) world.getTileEntity(x, y, z)
: null;
if (tile != null) tile.onPlaced();
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileReactorCore core) {
core.onPlaced();
}
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World p_149633_1_, int x, int y, int z) {
return AxisAlignedBB.getBoundingBox(0, 0, 0, 1, 1, 1); // super.getSelectedBoundingBoxFromPool(p_149633_1_, x,
// y, z);
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
return AxisAlignedBB.getBoundingBox(0, 0, 0, 1, 1, 1);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
// TileReactorCore tile = world.getTileEntity(x, y, z) instanceof TileReactorCore ? (TileReactorCore)
// world.getTileEntity(x, y, z) : null;
// if (tile != null) return tile.onStructureRightClicked(player);
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int p_149749_6_) {
TileReactorCore tile = world.getTileEntity(x, y, z) instanceof TileReactorCore
? (TileReactorCore) world.getTileEntity(x, y, z)
: null;
if (tile != null) tile.onBroken();
super.breakBlock(world, x, y, z, p_149749_5_, p_149749_6_);
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileReactorCore core) {
core.onBroken();
}
super.breakBlock(world, x, y, z, blockBroken, metadata);
}
}
@@ -1,5 +1,6 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -16,7 +17,6 @@ import com.brandon3055.draconicevolution.DraconicEvolution;
import com.brandon3055.draconicevolution.common.ModBlocks;
import com.brandon3055.draconicevolution.common.blocks.BlockDE;
import com.brandon3055.draconicevolution.common.lib.References;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorEnergyInjector;
import cpw.mods.fml.relauncher.Side;
@@ -25,7 +25,7 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 23/7/2015.
*/
public class ReactorEnergyInjector extends BlockDE {
public class ReactorEnergyInjector extends BlockDE implements ITileEntityProvider {
public ReactorEnergyInjector() {
this.setCreativeTab(DraconicEvolution.tabBlocksItems);
@@ -34,70 +34,36 @@ public class ReactorEnergyInjector extends BlockDE {
ModBlocks.register(this);
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "transparency");
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y, int z) {
TileReactorEnergyInjector tile = access.getTileEntity(x, y, z) instanceof TileReactorEnergyInjector
? (TileReactorEnergyInjector) access.getTileEntity(x, y, z)
: null;
if (tile != null) {
switch (tile.facingDirection) {
case 0:
this.setBlockBounds(0F, 0.885F, 0F, 1F, 1F, 1F);
break;
case 1:
this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F);
break;
case 2:
this.setBlockBounds(0F, 0F, 0.885F, 1F, 1F, 1F);
break;
case 3:
this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 0.125F);
break;
case 4:
this.setBlockBounds(0.885F, 0F, 0F, 1F, 1F, 1F);
break;
case 5:
this.setBlockBounds(0F, 0F, 0F, 0.125F, 1F, 1F);
break;
}
}
super.setBlockBoundsBasedOnState(access, x, y, z);
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
initializeBoundingBox(world, x, y, z);
super.setBlockBoundsBasedOnState(world, x, y, z);
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
TileReactorEnergyInjector tile = world.getTileEntity(x, y, z) instanceof TileReactorEnergyInjector
? (TileReactorEnergyInjector) world.getTileEntity(x, y, z)
: null;
if (tile != null) {
switch (tile.facingDirection) {
case 0:
this.setBlockBounds(0F, 0.885F, 0F, 1F, 1F, 1F);
break;
case 1:
this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F);
break;
case 2:
this.setBlockBounds(0F, 0F, 0.885F, 1F, 1F, 1F);
break;
case 3:
this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 0.125F);
break;
case 4:
this.setBlockBounds(0.885F, 0F, 0F, 1F, 1F, 1F);
break;
case 5:
this.setBlockBounds(0F, 0F, 0F, 0.125F, 1F, 1F);
break;
initializeBoundingBox(world, x, y, z);
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
private void initializeBoundingBox(IBlockAccess world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileReactorEnergyInjector injector) {
switch (injector.facing) {
case DOWN -> this.setBlockBounds(0F, 0.875F, 0F, 1F, 1F, 1F);
case UP -> this.setBlockBounds(0F, 0F, 0F, 1F, 0.125F, 1F);
case NORTH -> this.setBlockBounds(0F, 0F, 0.875F, 1F, 1F, 1F);
case SOUTH -> this.setBlockBounds(0F, 0F, 0F, 1F, 1F, 0.125F);
case WEST -> this.setBlockBounds(0.875F, 0F, 0F, 1F, 1F, 1F);
case EAST -> this.setBlockBounds(0F, 0F, 0F, 0.125F, 1F, 1F);
}
}
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
@Override
@@ -117,41 +83,36 @@ public class ReactorEnergyInjector extends BlockDE {
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
int d = Utills.determineOrientation(x, y, z, entity);
TileReactorEnergyInjector tile = (TileReactorEnergyInjector) world.getTileEntity(x, y, z);
tile.facingDirection = ForgeDirection.getOrientation(d).getOpposite().ordinal();
tile.onPlaced();
ForgeDirection facing = ForgeDirection.getOrientation(Utills.determineOrientation(x, y, z, entity));
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileReactorEnergyInjector injector) {
injector.facing = entity.isSneaking() ? facing.getOpposite() : facing;
injector.onPlaced();
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
IReactorPart tile = world.getTileEntity(x, y, z) instanceof IReactorPart
? (IReactorPart) world.getTileEntity(x, y, z)
: null;
if (tile != null && player.isSneaking()) {
tile.changeRedstoneMode();
if (!world.isRemote) player.addChatComponentMessage(new ChatComponentText(tile.getRedstoneModeString()));
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof IReactorPart part && player.isSneaking()) {
part.changeComparatorMode();
if (!world.isRemote) {
player.addChatComponentMessage(new ChatComponentText(part.getComparatorMode().toLocalizedString()));
}
return true;
}
return false;
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int p_149736_5_) {
IReactorPart tile = world.getTileEntity(x, y, z) instanceof IReactorPart
? (IReactorPart) world.getTileEntity(x, y, z)
: null;
if (tile == null) return 0;
TileReactorCore core = tile.getMaster().getTileEntity(world) instanceof TileReactorCore
? (TileReactorCore) tile.getMaster().getTileEntity(world)
: null;
if (core != null) return core.getComparatorOutput(tile.getRedstoneMode());
return 0;
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
return IReactorPart.getComparatorOutput(world, x, y, z);
}
@Override
@@ -160,7 +121,7 @@ public class ReactorEnergyInjector extends BlockDE {
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileReactorEnergyInjector();
}
}
@@ -1,6 +1,7 @@
package com.brandon3055.draconicevolution.common.blocks.multiblock;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -24,7 +25,7 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* Created by Brandon on 5/7/2015.
*/
public class ReactorStabilizer extends BlockDE {
public class ReactorStabilizer extends BlockDE implements ITileEntityProvider {
public ReactorStabilizer() {
this.setCreativeTab(DraconicEvolution.tabBlocksItems);
@@ -32,8 +33,8 @@ public class ReactorStabilizer extends BlockDE {
ModBlocks.register(this);
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
blockIcon = iconRegister.registerIcon(References.RESOURCESPREFIX + "transparency");
}
@@ -44,27 +45,20 @@ public class ReactorStabilizer extends BlockDE {
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_,
float p_149727_7_, float p_149727_8_, float p_149727_9_) {
if (!player.isSneaking()) {
TileReactorStabilizer tile = world.getTileEntity(x, y, z) instanceof TileReactorStabilizer
? (TileReactorStabilizer) world.getTileEntity(x, y, z)
: null;
TileEntity core = null;
if (tile != null) core = tile.getMaster().getTileEntity(world);
if (core instanceof TileReactorCore) {
((TileReactorCore) core).onStructureRightClicked(player);
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof IReactorPart part) {
if (player.isSneaking()) {
part.changeComparatorMode();
if (!world.isRemote) {
player.addChatComponentMessage(new ChatComponentText(part.getComparatorMode().toLocalizedString()));
}
return true;
}
} else if (!world.isRemote) {
IReactorPart tile = world.getTileEntity(x, y, z) instanceof IReactorPart
? (IReactorPart) world.getTileEntity(x, y, z)
: null;
if (tile != null) {
tile.changeRedstoneMode();
if (!world.isRemote)
player.addChatComponentMessage(new ChatComponentText(tile.getRedstoneModeString()));
return true;
TileReactorCore core = part.getMaster();
if (core != null) {
return core.onStructureRightClicked(player);
}
}
return false;
@@ -86,48 +80,38 @@ public class ReactorStabilizer extends BlockDE {
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileReactorStabilizer();
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
int d = Utills.determineOrientation(x, y, z, entity);
TileReactorStabilizer tile = world.getTileEntity(x, y, z) instanceof TileReactorStabilizer
? (TileReactorStabilizer) world.getTileEntity(x, y, z)
: null;
if (tile != null) {
if (entity.isSneaking()) tile.facingDirection = ForgeDirection.getOrientation(d).getOpposite().ordinal();
else tile.facingDirection = ForgeDirection.getOrientation(d).ordinal();
tile.onPlaced();
ForgeDirection facing = ForgeDirection.getOrientation(Utills.determineOrientation(x, y, z, entity));
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileReactorStabilizer stabilizer) {
stabilizer.facing = entity.isSneaking() ? facing.getOpposite() : facing;
stabilizer.onPlaced();
}
}
@Override
public void breakBlock(World world, int x, int y, int z, Block p_149749_5_, int p_149749_6_) {
TileReactorStabilizer tile = world.getTileEntity(x, y, z) instanceof TileReactorStabilizer
? (TileReactorStabilizer) world.getTileEntity(x, y, z)
: null;
TileEntity core = null;
if (tile != null) core = tile.getMaster().getTileEntity(world);
super.breakBlock(world, x, y, z, p_149749_5_, p_149749_6_);
if (core instanceof TileReactorCore) ((TileReactorCore) core).validateStructure();
public void breakBlock(World world, int x, int y, int z, Block blockBroken, int metadata) {
TileEntity tile = world.getTileEntity(x, y, z);
TileReactorCore core = tile instanceof IReactorPart part ? part.getMaster() : null;
super.breakBlock(world, x, y, z, blockBroken, metadata);
if (core != null) {
core.updateReactorParts(false);
core.validateStructure();
}
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int p_149736_5_) {
IReactorPart tile = world.getTileEntity(x, y, z) instanceof IReactorPart
? (IReactorPart) world.getTileEntity(x, y, z)
: null;
if (tile == null) return 0;
TileReactorCore core = tile.getMaster().getTileEntity(world) instanceof TileReactorCore
? (TileReactorCore) tile.getMaster().getTileEntity(world)
: null;
if (core != null) return core.getComparatorOutput(tile.getRedstoneMode());
return 0;
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
return IReactorPart.getComparatorOutput(world, x, y, z);
}
}
@@ -1,37 +1,24 @@
package com.brandon3055.draconicevolution.common.container;
import java.util.Iterator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.brandon3055.draconicevolution.client.gui.GUIPlayerDetector;
import com.brandon3055.draconicevolution.common.inventory.SlotOpaqueBlock;
import com.brandon3055.draconicevolution.common.tileentities.TilePlayerDetectorAdvanced;
public class ContainerPlayerDetector extends Container {
private TilePlayerDetectorAdvanced tileDetector;
private GUIPlayerDetector gui = null;
private boolean shouldShowInventory = true;
private final TilePlayerDetectorAdvanced detector;
public ContainerPlayerDetector(InventoryPlayer invPlayer, TilePlayerDetectorAdvanced tileDetector) {
this.tileDetector = tileDetector;
public ContainerPlayerDetector(InventoryPlayer playerInventory, TilePlayerDetectorAdvanced detector) {
this.detector = detector;
bindPlayerInventory(invPlayer);
addContainerSlots(tileDetector);
updateContainerSlots();
}
public ContainerPlayerDetector(InventoryPlayer invPlayer, TilePlayerDetectorAdvanced tileDetector,
GUIPlayerDetector gui) {
this.tileDetector = tileDetector;
this.gui = gui;
bindPlayerInventory(invPlayer);
addContainerSlots(tileDetector);
bindPlayerInventory(playerInventory);
addContainerSlots(detector);
updateContainerSlots();
}
@@ -52,40 +39,27 @@ public class ContainerPlayerDetector extends Container {
}
public void updateContainerSlots() {
if (gui == null) {
return;
}
Iterator<Slot> i1 = inventorySlots.iterator();
while (i1.hasNext()) {
Slot sl = i1.next();
if (sl instanceof SlotOpaqueBlock) {
if (gui.showInvSlots) {
sl.xDisplayPosition = 143;
sl.yDisplayPosition = 20;
for (Slot slot : (Iterable<Slot>) inventorySlots) {
if (slot instanceof SlotOpaqueBlock) {
if (shouldShowInventory) {
slot.xDisplayPosition = 143;
slot.yDisplayPosition = 20;
} else {
sl.xDisplayPosition = -1000;
sl.yDisplayPosition = -1000;
slot.xDisplayPosition = -1000;
slot.yDisplayPosition = -1000;
}
} else {
if (gui.showInvSlots) {
if (sl.slotNumber < 9) {
sl.xDisplayPosition = 8 + 18 * sl.slotNumber;
sl.yDisplayPosition = 174;
} else if (sl.slotNumber < 18) {
sl.xDisplayPosition = 8 + 18 * (sl.slotNumber - 9);
sl.yDisplayPosition = 116 + 0 * 18;
} else if (sl.slotNumber < 27) {
sl.xDisplayPosition = 8 + 18 * (sl.slotNumber - 18);
sl.yDisplayPosition = 116 + 1 * 18;
} else if (sl.slotNumber < 36) {
sl.xDisplayPosition = 8 + 18 * (sl.slotNumber - 27);
sl.yDisplayPosition = 116 + 2 * 18;
if (shouldShowInventory) {
if (slot.slotNumber < 9) {
slot.xDisplayPosition = 8 + 18 * slot.slotNumber;
slot.yDisplayPosition = 174;
} else if (slot.slotNumber < 36) {
slot.xDisplayPosition = 8 + 18 * (slot.slotNumber % 9);
slot.yDisplayPosition = 116 + (slot.slotNumber / 9 - 1) * 18;
}
} else {
sl.xDisplayPosition = -1000;
sl.yDisplayPosition = -1000;
slot.xDisplayPosition = -1000;
slot.yDisplayPosition = -1000;
}
}
}
@@ -93,53 +67,24 @@ public class ContainerPlayerDetector extends Container {
@Override
public boolean canInteractWith(EntityPlayer player) {
return tileDetector.isUseableByPlayer(player);
return detector.isUseableByPlayer(player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int i) {
// Slot slot = getSlot(i);
//
//
// if (slot != null && slot.getHasStack())
// {
// ItemStack stack = slot.getStack();
// ItemStack result = stack.copy();
// Block block = Block.getBlockFromItem(stack.getItem());
//
// if (i >= 36){
// if (!mergeItemStack(stack, 0, 36, false)){
// return null;
// }
// }else if (!(block.isOpaqueCube() && block.renderAsNormalBlock()) || !mergeItemStack(stack, 36, 36 +
// tileDetector.getSizeInventory(), false)){
// return null;
// }
//
// if (stack.stackSize == 0) {
// slot.putStack(null);
// }else{
// slot.onSlotChanged();
// }
//
// slot.onPickupFromSlot(player, stack);
//
// return result;
// }
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
return null;
}
public TilePlayerDetectorAdvanced getTileDetector() {
return tileDetector;
public boolean shouldShowInventory() {
return shouldShowInventory;
}
@Override
public ItemStack slotClick(int slot, int button, int par3, EntityPlayer par4EntityPlayer) {
return super.slotClick(slot, button, par3, par4EntityPlayer);
// if (par3 == 4)
// return super.slotClick(slot, button, 0, par4EntityPlayer);
// else
// return super.slotClick(slot, button, par3, par4EntityPlayer);
public void setShouldShowInventory(boolean shouldShow) {
shouldShowInventory = shouldShow;
updateContainerSlots();
}
public TilePlayerDetectorAdvanced getDetector() {
return detector;
}
}
@@ -1,83 +1,79 @@
package com.brandon3055.draconicevolution.common.container;
import java.util.Iterator;
import java.util.Set;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import com.brandon3055.draconicevolution.common.ModBlocks;
import com.brandon3055.draconicevolution.common.ModItems;
import com.brandon3055.draconicevolution.common.inventory.GenericInventory;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore.ReactorState;
import com.brandon3055.draconicevolution.common.utills.OreDictionaryHelper;
/**
* Created by brandon3055 on 30/7/2015.
*/
public class ContainerReactor extends ContainerDataSync {
private TileReactorCore reactor;
private EntityPlayer player;
private GenericInventory ioSlots = new GenericInventory() {
private static final int maximumFuelStorage = 10368;
private static final int nuggetFuelAmount = 16;
private static final int ingotFuelAmount = nuggetFuelAmount * 9;
private static final int blockFuelAmount = ingotFuelAmount * 9;
private final TileReactorCore core;
private final EntityPlayer player;
private final GenericInventory ioSlots = new GenericInventory() {
private ItemStack[] items = new ItemStack[2];
private final ItemStack[] items = new ItemStack[2];
@Override
public ItemStack[] getStorage() {
return items;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return true;
// return itemstack != null && (itemstack.getItem() == ModItems.draconicIngot || itemstack.getItem() ==
// Item.getItemFromBlock(ModBlocks.draconicBlock));
}
@Override
public int getInventoryStackLimit() {
return 1; // super.getInventoryStackLimit();
return 1;
}
@Override
public void setInventorySlotContents(int i, ItemStack stack) {
if (i == 0 && stack != null
&& (stack.getItem() == ModItems.draconicIngot
|| stack.getItem() == Item.getItemFromBlock(ModBlocks.draconicBlock)
|| (stack.getItem() == ModItems.nugget && stack.getItemDamage() == 1))) {
if (stack.getItem() == ModItems.nugget) reactor.reactorFuel += stack.stackSize * 16;
if (stack.getItem() == ModItems.draconicIngot) reactor.reactorFuel += stack.stackSize * 144;
if (stack.getItem() == Item.getItemFromBlock(ModBlocks.draconicBlock))
reactor.reactorFuel += stack.stackSize * 1296;
reactor.validateStructure();
} else getStorage()[i] = stack;
public void setInventorySlotContents(int slot, ItemStack stack) {
if (slot == 0) {
Set<String> oreNames = OreDictionaryHelper.getOreNames(stack);
if (oreNames.contains("blockDraconiumAwakened")) {
core.reactorFuel += stack.stackSize * blockFuelAmount;
} else if (oreNames.contains("ingotDraconiumAwakened")) {
core.reactorFuel += stack.stackSize * ingotFuelAmount;
} else if (oreNames.contains("nuggetDraconiumAwakened")) {
core.reactorFuel += stack.stackSize * nuggetFuelAmount;
}
} else {
items[slot] = stack;
}
}
@Override
public void markDirty() {
super.markDirty();
core.markDirty();
}
};
// Syncing //todo sort out syncing
public int LTConversionUnit = -1;
public int LTReactionIntensity = -1;
// public int LTMaxReactIntensity = -1;
// public int LTFieldStrength = -1;
// public int LTMaxFieldStrength = -1;
// public int LTEnergySaturation = -1;
// public int LTMaxEnergySaturation = -1;
// public int LTFuelConversion = -1;
private int conversionUnitCache = -1;
private int tempDrainFactorCache = -1;
private int generationRateCache = -1;
private int fieldDrainCache = -1;
private int fuelUseRateCache = -1;
private boolean isOfflineCache;
public double LTTempDrainFactor = -1;
public double LTGenerationRate = -1;
public int LTFieldDrain = -1;
public double LTFuelUseRate = -1;
public boolean LTOffline;
// #######
public ContainerReactor(EntityPlayer player, TileReactorCore reactor) {
this.reactor = reactor;
public ContainerReactor(EntityPlayer player, TileReactorCore core) {
this.core = core;
this.player = player;
this.LTOffline = reactor.reactorState == TileReactorCore.STATE_OFFLINE;
this.isOfflineCache = core.reactorState == ReactorState.OFFLINE;
for (int x = 0; x < 9; x++) {
addSlotToContainer(new Slot(player.inventory, x, 44 + 18 * x, 198));
@@ -89,12 +85,21 @@ public class ContainerReactor extends ContainerDataSync {
}
}
if (reactor.reactorState == TileReactorCore.STATE_OFFLINE) {
addSlotToContainer(new SlotInsert(ioSlots, 0, 15, 140, reactor));
addSlotToContainer(new SlotExtract(ioSlots, 1, 217, 140));
if (core.reactorState == ReactorState.OFFLINE) {
addFuelSlots();
}
}
private void addFuelSlots() {
addSlotToContainer(new SlotInsert(ioSlots, 0, 15, 140, core));
addSlotToContainer(new SlotExtract(ioSlots, 1, 217, 140));
}
@SuppressWarnings("unchecked")
private void removeFuelSlots() {
inventorySlots.removeIf(o -> o instanceof SlotExtract || o instanceof SlotInsert);
}
@Override
public void onContainerClosed(EntityPlayer entityPlayer) {
if (ioSlots.getStackInSlot(1) != null && !player.worldObj.isRemote) {
@@ -116,158 +121,141 @@ public class ContainerReactor extends ContainerDataSync {
}
@Override
public void detectAndSendChanges() { // todo check what values are being synced by the tile and remove them from
// here
if (LTOffline && reactor.reactorState != TileReactorCore.STATE_OFFLINE) {
Iterator i = inventorySlots.iterator();
while (i.hasNext()) {
Object o = i.next();
if (o instanceof SlotExtract || o instanceof SlotInsert) i.remove();
}
public void detectAndSendChanges() {
if (isOfflineCache && core.reactorState != ReactorState.OFFLINE) {
removeFuelSlots();
sendObjectToClient(null, 99, 1);
} else if (!LTOffline && reactor.reactorState == TileReactorCore.STATE_OFFLINE) {
addSlotToContainer(new SlotInsert(ioSlots, 0, 15, 140, reactor));
addSlotToContainer(new SlotExtract(ioSlots, 1, 217, 140));
} else if (!isOfflineCache && core.reactorState == ReactorState.OFFLINE) {
addFuelSlots();
sendObjectToClient(null, 98, 1);
}
LTOffline = reactor.reactorState == TileReactorCore.STATE_OFFLINE;
isOfflineCache = core.reactorState == ReactorState.OFFLINE;
if (reactor.conversionUnit != LTConversionUnit)
LTConversionUnit = (Integer) sendObjectToClient(null, 0, (int) (reactor.conversionUnit * 100));
// if ((int)reactor.reactionTemperature != LTReactionIntensity)LTReactionIntensity = (Integer)
// sendObjectToClient(null, 1, (int) reactor.reactionTemperature);
// if ((int)reactor.maxReactTemperature != LTMaxReactIntensity)LTMaxReactIntensity = (Integer)
// sendObjectToClient(null, 2, (int) reactor.maxReactTemperature);
// if ((int)reactor.fieldCharge != LTFieldStrength) LTFieldStrength = (Integer) sendObjectToClient(null,
// 3, (int) reactor.fieldCharge);
// if ((int)reactor.maxFieldCharge != LTMaxFieldStrength) LTMaxFieldStrength = (Integer)
// sendObjectToClient(null, 7, (int) reactor.maxFieldCharge);
// if (reactor.energySaturation != LTEnergySaturation) LTEnergySaturation = (Integer)
// sendObjectToClient(null, 4, reactor.energySaturation);
// if (reactor.maxEnergySaturation != LTMaxEnergySaturation) LTMaxEnergySaturation = (Integer)
// sendObjectToClient(null, 5, reactor.maxEnergySaturation);
// if (reactor.convertedFuel != LTFuelConversion) LTFuelConversion = (Integer) sendObjectToClient(null,
// 6, reactor.convertedFuel);
/* if (reactor.tempDrainFactor != LTTempDrainFactor) LTTempDrainFactor = (Integer) */
sendObjectToClient(null, 8, (int) (reactor.tempDrainFactor * 1000D));
if (reactor.generationRate != LTGenerationRate)
LTGenerationRate = (Integer) sendObjectToClient(null, 9, (int) (reactor.generationRate));
if (reactor.fieldDrain != LTFieldDrain)
LTFieldDrain = (Integer) sendObjectToClient(null, 10, reactor.fieldDrain);
/* if (reactor.fuelUseRate != LTFuelUseRate) LTFuelUseRate = (Integer) */
sendObjectToClient(null, 11, (int) (reactor.fuelUseRate * 1000000D));
int conversionUnit = (int) (core.conversionUnit * 100);
if (conversionUnit != conversionUnitCache) {
conversionUnitCache = (int) sendObjectToClient(null, 0, conversionUnit);
}
int tempDrainFactor = (int) (core.tempDrainFactor * 1000);
if (tempDrainFactor != tempDrainFactorCache) {
tempDrainFactorCache = (int) sendObjectToClient(null, 8, tempDrainFactor);
}
int generationRate = (int) core.generationRate;
if (generationRate != generationRateCache) {
generationRateCache = (int) sendObjectToClient(null, 9, generationRate);
}
if (core.fieldDrain != fieldDrainCache) {
fieldDrainCache = (int) sendObjectToClient(null, 10, core.fieldDrain);
}
int fuelUseRate = (int) (core.fuelUseRate * 1000000);
if (fuelUseRate != fuelUseRateCache) {
fuelUseRateCache = (int) sendObjectToClient(null, 11, fuelUseRate);
}
super.detectAndSendChanges();
}
@Override
public void receiveSyncData(int index, int value) {
if (index == 0) reactor.conversionUnit = (double) value / 100D;
// else if (index == 1) reactor.reactionTemperature = value;
// else if (index == 2) reactor.maxReactTemperature = value;
// else if (index == 3) reactor.fieldCharge = value;
// else if (index == 4) reactor.energySaturation = value;
// else if (index == 5) reactor.maxEnergySaturation = value;
// else if (index == 6) reactor.convertedFuel = value;
// else if (index == 7) reactor.maxFieldCharge = value;
else if (index == 8) reactor.tempDrainFactor = value / 1000D;
else if (index == 9) reactor.generationRate = value;
else if (index == 10) reactor.fieldDrain = value;
else if (index == 11) reactor.fuelUseRate = value / 1000000D;
if (index == 20) reactor.processButtonPress(value);
if (index == 0) {
core.conversionUnit = (double) value / 100D;
} else if (index == 8) {
core.tempDrainFactor = value / 1000D;
} else if (index == 9) {
core.generationRate = value;
} else if (index == 10) {
core.fieldDrain = value;
} else if (index == 11) {
core.fuelUseRate = value / 1000000D;
}
if (index == 20) {
core.processButtonPress(value);
}
if (index == 99) {
Iterator i = inventorySlots.iterator();
while (i.hasNext()) {
Object o = i.next();
if (o instanceof SlotExtract || o instanceof SlotInsert) i.remove();
}
removeFuelSlots();
} else if (index == 98) {
addSlotToContainer(new SlotInsert(ioSlots, 0, 15, 140, reactor));
addSlotToContainer(new SlotExtract(ioSlots, 1, 217, 140));
addFuelSlots();
}
}
@Override
public ItemStack slotClick(int slot, int button, int p_75144_3_, EntityPlayer player1) {
if (slot == 37 && player1.inventory.getItemStack() == null) {
if (reactor.reactorFuel / 144 >= 64) {
int i = reactor.reactorFuel / 1296;
int i2 = Math.min(64, i);
ioSlots.getStorage()[1] = new ItemStack(ModBlocks.draconicBlock, i2);
reactor.reactorFuel -= i2 * 1296;
} else if (reactor.reactorFuel >= 144) {
int i = reactor.reactorFuel / 144;
int i2 = Math.min(64, i);
ioSlots.getStorage()[1] = new ItemStack(ModItems.draconicIngot, i2);
reactor.reactorFuel -= i2 * 144;
} else if (reactor.reactorFuel >= 16) {
int i = reactor.reactorFuel / 16;
int i2 = Math.min(64, i);
ioSlots.getStorage()[1] = new ItemStack(ModItems.nugget, i2, 1);
reactor.reactorFuel -= i2 * 16;
} else if (reactor.convertedFuel / 144 >= 64) {
int i = reactor.convertedFuel / 1296;
int i2 = Math.min(64, i);
ioSlots.getStorage()[1] = new ItemStack(ModItems.chaosFragment, i2, 2);
reactor.convertedFuel -= i2 * 1296;
} else if (reactor.convertedFuel >= 144) {
int i = reactor.convertedFuel / 144;
int i2 = Math.min(64, i);
ioSlots.getStorage()[1] = new ItemStack(ModItems.chaosFragment, i2, 1);
reactor.convertedFuel -= i2 * 144;
} else if (reactor.convertedFuel >= 16) {
int i = reactor.convertedFuel / 16;
int i2 = Math.min(64, i);
ioSlots.getStorage()[1] = new ItemStack(ModItems.chaosFragment, i2, 0);
reactor.convertedFuel -= i2 * 16;
public ItemStack slotClick(int slot, int button, int mode, EntityPlayer player) {
if (slot == 37 && player.inventory.getItemStack() == null) {
if (core.reactorFuel / ingotFuelAmount >= 64) {
int stackSize = core.reactorFuel / blockFuelAmount;
stackSize = Math.min(64, stackSize);
ioSlots.setInventorySlotContents(1, new ItemStack(ModBlocks.draconicBlock, stackSize));
core.reactorFuel -= stackSize * blockFuelAmount;
} else if (core.reactorFuel >= ingotFuelAmount) {
int stackSize = core.reactorFuel / ingotFuelAmount;
stackSize = Math.min(64, stackSize);
ioSlots.setInventorySlotContents(1, new ItemStack(ModItems.draconicIngot, stackSize));
core.reactorFuel -= stackSize * ingotFuelAmount;
} else if (core.reactorFuel >= nuggetFuelAmount) {
int stackSize = core.reactorFuel / nuggetFuelAmount;
ioSlots.setInventorySlotContents(1, new ItemStack(ModItems.nugget, stackSize, 1));
core.reactorFuel -= stackSize * nuggetFuelAmount;
} else if (core.convertedFuel / ingotFuelAmount >= 64) {
int stackSize = core.convertedFuel / blockFuelAmount;
stackSize = Math.min(64, stackSize);
ioSlots.setInventorySlotContents(1, new ItemStack(ModItems.chaosFragment, stackSize, 2));
core.convertedFuel -= stackSize * blockFuelAmount;
} else if (core.convertedFuel >= ingotFuelAmount) {
int stackSize = core.convertedFuel / ingotFuelAmount;
stackSize = Math.min(64, stackSize);
ioSlots.setInventorySlotContents(1, new ItemStack(ModItems.chaosFragment, stackSize, 1));
core.convertedFuel -= stackSize * ingotFuelAmount;
} else if (core.convertedFuel >= nuggetFuelAmount) {
int stackSize = core.convertedFuel / nuggetFuelAmount;
ioSlots.setInventorySlotContents(1, new ItemStack(ModItems.chaosFragment, stackSize, 0));
core.convertedFuel -= stackSize * nuggetFuelAmount;
}
}
return super.slotClick(slot, button, p_75144_3_, player1);
return super.slotClick(slot, button, mode, player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
return null;
}
public static class SlotInsert extends Slot {
private int numberAllowed = -1;
private TileReactorCore reactor;
private int stackSizeLimit = 0;
private final TileReactorCore core;
public SlotInsert(IInventory iInventory, int iSlot, int x, int y, TileReactorCore reactor) {
super(iInventory, iSlot, x, y);
this.reactor = reactor;
public SlotInsert(IInventory inventory, int slot, int x, int y, TileReactorCore core) {
super(inventory, slot, x, y);
this.core = core;
}
@Override
public boolean isItemValid(ItemStack stack) {
if (stack == null) return false;
else if (stack.getItem() == ModItems.nugget && stack.getItemDamage() == 1)
numberAllowed = (10368 - (reactor.reactorFuel + reactor.convertedFuel)) / 16;
else if (stack.getItem() == ModItems.draconicIngot)
numberAllowed = (10368 - (reactor.reactorFuel + reactor.convertedFuel)) / 144;
else if (stack.getItem() == Item.getItemFromBlock(ModBlocks.draconicBlock))
numberAllowed = (10368 - (reactor.reactorFuel + reactor.convertedFuel)) / 1296;
else return false;
return numberAllowed > 0;
if (stack == null) {
return false;
}
Set<String> oreNames = OreDictionaryHelper.getOreNames(stack);
if (oreNames.contains("nuggetDraconiumAwakened")) {
stackSizeLimit = (maximumFuelStorage - (core.reactorFuel + core.convertedFuel)) / nuggetFuelAmount;
} else if (oreNames.contains("ingotDraconiumAwakened")) {
stackSizeLimit = (maximumFuelStorage - (core.reactorFuel + core.convertedFuel)) / ingotFuelAmount;
} else if (oreNames.contains("blockDraconiumAwakened")) {
stackSizeLimit = (maximumFuelStorage - (core.reactorFuel + core.convertedFuel)) / blockFuelAmount;
} else {
return false;
}
return stackSizeLimit > 0;
}
@Override
public int getSlotStackLimit() {
return numberAllowed;
return stackSizeLimit;
}
}
public static class SlotExtract extends Slot {
private GenericInventory inventory;
public SlotExtract(GenericInventory iInventory, int iSlot, int x, int y) {
super(iInventory, iSlot, x, y);
inventory = iInventory;
public SlotExtract(GenericInventory inventory, int slot, int x, int y) {
super(inventory, slot, x, y);
}
@Override
@@ -54,7 +54,7 @@ public class ChaosImplosionTrace implements IProcess {
List<Entity> entities = worldObj.getEntitiesWithinAABB(
Entity.class,
AxisAlignedBB.getBoundingBox(xCoord, y, zCoord, xCoord + 1, y + 1, zCoord + 1));
for (Entity entity : entities) entity.attackEntityFrom(ReactorExplosion.fusionExplosion, power * 100);
for (Entity entity : entities) entity.attackEntityFrom(ReactorExplosion.FUSION_EXPLOSION, power * 100);
// energy -= block instanceof BlockLiquid ? 10 : block.getExplosionResistance(null);
if (energy >= 0) worldObj.setBlockToAir(xCoord, y, zCoord);
@@ -1,7 +1,7 @@
package com.brandon3055.draconicevolution.common.network;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -9,7 +9,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import com.brandon3055.draconicevolution.common.tileentities.TileParticleGenerator;
import com.brandon3055.draconicevolution.common.utills.LogHelper;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
@@ -18,7 +17,7 @@ import io.netty.buffer.ByteBuf;
public class ParticleGenPacket implements IMessage {
byte buttonId = 0;
byte id = 0;
short value = 0;
int tileX = 0;
int tileY = 0;
@@ -26,8 +25,8 @@ public class ParticleGenPacket implements IMessage {
public ParticleGenPacket() {}
public ParticleGenPacket(byte buttonId, short value, int x, int y, int z) {
this.buttonId = buttonId;
public ParticleGenPacket(byte id, short value, int x, int y, int z) {
this.id = id;
this.value = value;
this.tileX = x;
this.tileY = y;
@@ -36,7 +35,7 @@ public class ParticleGenPacket implements IMessage {
@Override
public void toBytes(ByteBuf bytes) {
bytes.writeByte(buttonId);
bytes.writeByte(id);
bytes.writeShort(value);
bytes.writeInt(tileX);
bytes.writeInt(tileY);
@@ -45,7 +44,7 @@ public class ParticleGenPacket implements IMessage {
@Override
public void fromBytes(ByteBuf bytes) {
this.buttonId = bytes.readByte();
this.id = bytes.readByte();
this.value = bytes.readShort();
this.tileX = bytes.readInt();
this.tileY = bytes.readInt();
@@ -58,267 +57,73 @@ public class ParticleGenPacket implements IMessage {
public IMessage onMessage(ParticleGenPacket message, MessageContext ctx) {
TileEntity tile = ctx.getServerHandler().playerEntity.worldObj
.getTileEntity(message.tileX, message.tileY, message.tileZ);
TileParticleGenerator gen = (tile != null && tile instanceof TileParticleGenerator)
? (TileParticleGenerator) tile
: null;
if (gen != null) {
// System.out.println(buttonId + " " + value);
switch (message.buttonId) {
case 0: // red
gen.red = (int) message.value;
break;
case 1: // green
gen.green = (int) message.value;
break;
case 2: // blue
gen.blue = (int) message.value;
break;
case 3: // mx
gen.motion_x = (float) message.value / 1000F;
break;
case 4: // my
gen.motion_y = (float) message.value / 1000F;
break;
case 5: // mz
gen.motion_z = (float) message.value / 1000F;
break;
case 6: // ged
gen.red = (int) message.value;
break;
case 7: // green
gen.green = (int) message.value;
break;
case 8: // blue
gen.blue = (int) message.value;
break;
case 9: // mx
gen.motion_x = (float) message.value / 1000F;
break;
case 10: // my
gen.motion_y = (float) message.value / 1000F;
break;
case 11: // mz
gen.motion_z = (float) message.value / 1000F;
break;
case 12: // red
gen.random_red = (int) message.value;
break;
case 13: // green
gen.random_green = (int) message.value;
break;
case 14: // blue
gen.random_blue = (int) message.value;
break;
case 15: // mx
gen.random_motion_x = (float) message.value / 1000F;
break;
case 16: // my
gen.random_motion_y = (float) message.value / 1000F;
break;
case 17: // mz
gen.random_motion_z = (float) message.value / 1000F;
break;
case 18: // ged
gen.random_red = (int) message.value;
break;
case 19: // green
gen.random_green = (int) message.value;
break;
case 20: // blue
gen.random_blue = (int) message.value;
break;
case 21: // mx
gen.random_motion_x = (float) message.value / 1000F;
break;
case 22: // my
gen.random_motion_y = (float) message.value / 1000F;
break;
case 23: // mz
gen.random_motion_z = (float) message.value / 1000F;
break;
case 24: // Life +
gen.life = (int) message.value;
break;
case 25: // Life -
gen.life = (int) message.value;
break;
case 26: // RLife +
gen.random_life = (int) message.value;
break;
case 27: // RLife -
gen.random_life = (int) message.value;
break;
case 28: // Size +
gen.scale = (float) message.value / 100F;
break;
case 29: // Size -
gen.scale = (float) message.value / 100F;
break;
case 30: // RSize +
gen.random_scale = (float) message.value / 100F;
break;
case 31: // RSize -
gen.random_scale = (float) message.value / 100F;
break;
case 32: // SX +
gen.page = (int) message.value;
break;
case 33: // SX -
gen.page = (int) message.value;
break;
case 34: // SX +
gen.spawn_x = (float) message.value / 100F;
break;
case 35: // SX -
gen.spawn_x = (float) message.value / 100F;
break;
case 36: // RSX +
gen.random_spawn_x = (float) message.value / 100F;
break;
case 37: // RSX -
gen.random_spawn_x = (float) message.value / 100F;
break;
case 38: // SY +
gen.spawn_y = (float) message.value / 100F;
break;
case 39: // SY -
gen.spawn_y = (float) message.value / 100F;
break;
case 40: // RSY +
gen.random_spawn_y = (float) message.value / 100F;
break;
case 41: // RSY -
gen.random_spawn_y = (float) message.value / 100F;
break;
case 42: // SZ +
gen.spawn_z = (float) message.value / 100F;
break;
case 43: // SZ -
gen.spawn_z = (float) message.value / 100F;
break;
case 44: // RSZ +
gen.random_spawn_z = (float) message.value / 100F;
break;
case 45: // RSZ -
gen.random_spawn_z = (float) message.value / 100F;
break;
case 46: // Delay -
gen.spawn_rate = (int) message.value;
break;
case 47: // Delay -
gen.spawn_rate = (int) message.value;
break;
case 48: // Fade -
gen.fade = (int) message.value;
break;
case 49: // Fade -
gen.fade = (int) message.value;
break;
case 50: // Collision -
gen.collide = message.value == 0 ? false : true;
break;
case 51: // Particle Selected -
gen.selected_particle = (int) message.value;
break;
case 52: // Gravity +
gen.gravity = (float) message.value / 1000F;
break;
case 53: // Gravity -
gen.gravity = (float) message.value / 1000F;
break;
case 54: // Info Page (3)
gen.page = (int) message.value;
break;
case 55: // Back
gen.page = (int) message.value;
break;
case 58: // Back
LogHelper.info(message.value);
gen.particles_enabled = message.value == 1;
break;
if (!(tile instanceof TileParticleGenerator particleGenerator)) {
return null;
}
switch (message.id) {
case 0 -> particleGenerator.red = message.value;
case 1 -> particleGenerator.green = message.value;
case 2 -> particleGenerator.blue = message.value;
case 3 -> particleGenerator.motionX = (float) message.value / 1000F;
case 4 -> particleGenerator.motionY = (float) message.value / 1000F;
case 5 -> particleGenerator.motionZ = (float) message.value / 1000F;
case 6 -> particleGenerator.scale = (float) message.value / 100F;
case 7 -> particleGenerator.life = message.value;
case 10 -> particleGenerator.randomRed = message.value;
case 11 -> particleGenerator.randomGreen = message.value;
case 12 -> particleGenerator.randomBlue = message.value;
case 13 -> particleGenerator.randomMotionX = (float) message.value / 1000F;
case 14 -> particleGenerator.randomMotionY = (float) message.value / 1000F;
case 15 -> particleGenerator.randomMotionZ = (float) message.value / 1000F;
case 16 -> particleGenerator.randomScale = (float) message.value / 100F;
case 17 -> particleGenerator.randomLife = message.value;
case 20 -> particleGenerator.spawnX = (float) message.value / 10F;
case 21 -> particleGenerator.spawnY = (float) message.value / 10F;
case 22 -> particleGenerator.spawnZ = (float) message.value / 10F;
case 23 -> particleGenerator.spawnRate = message.value;
case 24 -> particleGenerator.fade = message.value;
case 25 -> particleGenerator.gravity = (float) message.value / 1000F;
case 30 -> particleGenerator.randomSpawnX = (float) message.value / 10F;
case 31 -> particleGenerator.randomSpawnY = (float) message.value / 10F;
case 32 -> particleGenerator.randomSpawnZ = (float) message.value / 10F;
case 40 -> particleGenerator.beamRed = message.value;
case 41 -> particleGenerator.beamGreen = message.value;
case 42 -> particleGenerator.beamBlue = message.value;
case 43 -> particleGenerator.beamPitch = (float) message.value / 10F;
case 44 -> particleGenerator.beamYaw = (float) message.value / 10F;
case 45 -> particleGenerator.beamRotation = (float) message.value / 100F;
case 46 -> particleGenerator.beamScale = (float) message.value / 100F;
case 47 -> particleGenerator.beamLength = (float) message.value / 100F;
case 100, 101, 102, 103 -> particleGenerator.page = message.value;
case 110 -> particleGenerator.canParticleCollide = message.value == 1;
case 111 -> particleGenerator.selectedParticle = message.value;
case 112 -> particleGenerator.isParticlesEnabled = message.value == 1;
case 120 -> particleGenerator.isBeamEnabled = message.value == 1;
case 121 -> particleGenerator.shouldRenderCore = message.value == 1;
}
case 100: // beam red +
gen.beam_red = message.value;
break;
case 101: // beam green +
gen.beam_green = message.value;
break;
case 102: // beam blue +
gen.beam_blue = message.value;
break;
case 103: // beam pitch +
gen.beam_pitch = (float) message.value / 100F;
break;
case 104: // beam yaw +
gen.beam_yaw = (float) message.value / 100F;
break;
case 105: // beam length +
gen.beam_length = (float) message.value / 100F;
break;
case 106: // beam rotation +
gen.beam_rotation = (float) message.value / 100F;
break;
case 107: // beam scale +
gen.beam_scale = (float) message.value / 100F;
break;
case 108: // beam red -
gen.beam_red = message.value;
break;
case 109: // beam green -
gen.beam_green = message.value;
break;
case 110: // beam blue -
gen.beam_blue = message.value;
break;
case 111: // beam pitch -
gen.beam_pitch = (float) message.value / 100F;
break;
case 112: // beam yaw -
gen.beam_yaw = (float) message.value / 100F;
break;
case 113: // beam length -
gen.beam_length = (float) message.value / 100F;
break;
case 114: // beam rotation -
gen.beam_rotation = (float) message.value / 100F;
break;
case 115: // beam scale -
gen.beam_scale = (float) message.value / 100F;
break;
case 116: // beam enabled
gen.beam_enabled = message.value == 1;
break;
case 117: // beam enabled
gen.render_core = message.value == 1;
break;
}
if (message.buttonId == 127) {
if (ctx.getServerHandler().playerEntity.capabilities.isCreativeMode
|| ctx.getServerHandler().playerEntity.inventory.hasItem(Items.paper)) {
giveNote(message, ctx);
} else ctx.getServerHandler().playerEntity.addChatComponentMessage(
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
if (message.id == 127) {
if (player.capabilities.isCreativeMode || player.inventory.hasItem(Items.paper)) {
giveNote(message, player);
} else {
player.addChatComponentMessage(
new ChatComponentText("You need paper in your inventory to do that"));
}
ctx.getServerHandler().playerEntity.worldObj
.markBlockForUpdate(message.tileX, message.tileY, message.tileZ);
}
player.worldObj.markBlockForUpdate(message.tileX, message.tileY, message.tileZ);
return null;
}
private void giveNote(ParticleGenPacket message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().playerEntity;
if (!player.capabilities.isCreativeMode) player.inventory.consumeInventoryItem(Items.paper);
private void giveNote(ParticleGenPacket message, EntityPlayerMP player) {
if (!player.capabilities.isCreativeMode) {
player.inventory.consumeInventoryItem(Items.paper);
}
ItemStack stack = new ItemStack(Items.paper);
stack.setTagCompound(new NBTTagCompound());
TileEntity tile = ctx.getServerHandler().playerEntity.worldObj
.getTileEntity(message.tileX, message.tileY, message.tileZ);
TileParticleGenerator gen = (tile != null && tile instanceof TileParticleGenerator)
? (TileParticleGenerator) tile
: null;
if (gen != null) {
gen.getBlockNBT(stack.getTagCompound());
TileEntity tile = player.worldObj.getTileEntity(message.tileX, message.tileY, message.tileZ);
if (tile instanceof TileParticleGenerator particleGenerator) {
particleGenerator.getBlockNBT(stack.getTagCompound());
stack.setStackDisplayName("Saved Particle Gen Settings");
player.worldObj.spawnEntityInWorld(
new EntityItem(player.worldObj, player.posX, player.posY, player.posZ, stack));
@@ -36,28 +36,20 @@ public class PlayerDetectorButtonPacket implements IMessage {
@Override
public IMessage onMessage(PlayerDetectorButtonPacket message, MessageContext ctx) {
ContainerPlayerDetector container = (ctx
.getServerHandler().playerEntity.openContainer instanceof ContainerPlayerDetector)
? (ContainerPlayerDetector) ctx.getServerHandler().playerEntity.openContainer
: null;
TilePlayerDetectorAdvanced tile = (container != null)
? ((ContainerPlayerDetector) container).getTileDetector()
: null;
if (tile != null) {
switch (message.index) {
case 0:
tile.range = message.value;
break;
case 1:
tile.whiteList = message.value == 1;
break;
case 2:
tile.outputInverted = message.value == 1;
break;
}
ctx.getServerHandler().playerEntity.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
if (!(ctx.getServerHandler().playerEntity.openContainer instanceof ContainerPlayerDetector container)) {
return null;
}
TilePlayerDetectorAdvanced tile = container.getDetector();
if (tile == null) {
return null;
}
switch (message.index) {
case 0 -> tile.range = message.value;
case 1 -> tile.isInWhiteListMode = message.value == 1;
case 2 -> tile.isOutputInverted = message.value == 1;
}
ctx.getServerHandler().playerEntity.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
return null;
}
}
@@ -37,16 +37,16 @@ public class PlayerDetectorStringPacket implements IMessage {
@Override
public IMessage onMessage(PlayerDetectorStringPacket message, MessageContext ctx) {
ContainerPlayerDetector container = (ctx
.getServerHandler().playerEntity.openContainer instanceof ContainerPlayerDetector)
? (ContainerPlayerDetector) ctx.getServerHandler().playerEntity.openContainer
: null;
TilePlayerDetectorAdvanced tile = (container != null) ? container.getTileDetector() : null;
if (tile != null) {
tile.names[message.index] = message.name;
ctx.getServerHandler().playerEntity.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
if (!(ctx.getServerHandler().playerEntity.openContainer instanceof ContainerPlayerDetector container)) {
return null;
}
TilePlayerDetectorAdvanced detector = container.getDetector();
if (detector == null) {
return null;
}
detector.names[message.index] = message.name;
ctx.getServerHandler().playerEntity.worldObj
.markBlockForUpdate(detector.xCoord, detector.yCoord, detector.zCoord);
return null;
}
}
@@ -25,85 +25,57 @@ public class TileCKeyStone extends TileEntity {
@Override
public void updateEntity() {
if (isActivated && (getMeta() == 1 || getMeta() == 3)) {
if (isActivated && (blockMetadata == 1 || blockMetadata == 3)) {
activeTicks++;
if (activeTicks >= delay) {
activeTicks = 0;
isActivated = false;
updateBlocks();
worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
"random.click",
0.3F,
0.5F);
worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.click", 0.3F, 0.5F);
}
}
}
public boolean onActivated(ItemStack stack, EntityPlayer player) {
if (stack == null || stack.getItem() != ModItems.key) {
if (player.capabilities.isCreativeMode && stack == null
&& player.isSneaking()
&& (getMeta() == 1 || getMeta() == 3))
if (stack == null && player.capabilities.isCreativeMode) {
if (player.isSneaking() && (blockMetadata == 1 || blockMetadata == 3)) {
delay += 5;
if (player.capabilities.isCreativeMode && stack == null) giveInformation(player);
}
giveInformation(player);
}
if (stack == null || stack.getItem() != ModItems.key) {
return false;
}
if (isMasterKey(stack)) {
return true;
}
if (setKey(stack)) {
return true;
}
if (!isKeyValid(stack, player)) {
return false;
}
if (isMasterKey(stack)) return true;
if (setKey(stack)) return true;
if (!isKeyValid(stack, player)) return false;
switch (getMeta()) {
switch (blockMetadata) {
case 0: // Permanent Activation
isActivated = true;
player.destroyCurrentEquippedItem();
worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
"random.click",
0.3F,
0.6F);
break;
case 1: // Button Activation
isActivated = true;
worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
"random.click",
0.3F,
0.6F);
break;
case 2: // Toggle Activation
if (!isActivated) worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
"random.click",
0.3F,
0.6F);
else worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
"random.click",
0.3F,
0.5F);
isActivated = !isActivated;
break;
case 3: // Button Activation (Consume Key)
isActivated = true;
player.destroyCurrentEquippedItem();
worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.click", 0.3F, 0.6F);
break;
case 1: // Button Activation
isActivated = true;
worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.click", 0.3F, 0.6F);
break;
case 2: // Toggle Activation
isActivated = !isActivated;
worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
xCoord + 0.5D,
yCoord + 0.5D,
zCoord + 0.5D,
"random.click",
0.3F,
0.6F);
isActivated ? 0.6F : 0.5F);
break;
case 4:
break;
@@ -115,30 +87,25 @@ public class TileCKeyStone extends TileEntity {
private void giveInformation(EntityPlayer player) {
if (worldObj.isRemote) {
player.addChatComponentMessage(new ChatComponentTranslation("msg.cKeyStoneType" + getMeta() + ".txt"));
player.addChatComponentMessage(new ChatComponentTranslation("msg.cKeyStoneType" + blockMetadata + ".txt"));
player.addChatComponentMessage(new ChatComponentText("Key: " + keyCode));
if (getMeta() == 1 || getMeta() == 3) player.addChatComponentMessage(
new ChatComponentText("Delay: " + delay + "t (" + (((double) delay) / 20D) + "s)"));
if (blockMetadata == 1 || blockMetadata == 3) {
player.addChatComponentMessage(
new ChatComponentText("Delay: " + delay + "t (" + (((double) delay) / 20D) + "s)"));
}
}
}
private boolean isMasterKey(ItemStack key) {
if (key.getItemDamage() == 1) {
if (!isActivated) worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
"random.click",
0.3F,
0.6F);
else worldObj.playSoundEffect(
(double) xCoord + 0.5D,
(double) yCoord + 0.5D,
(double) zCoord + 0.5D,
"random.click",
0.3F,
0.5F);
isActivated = !isActivated;
worldObj.playSoundEffect(
xCoord + 0.5D,
yCoord + 0.5D,
zCoord + 0.5D,
"random.click",
0.3F,
isActivated ? 0.6F : 0.5F);
updateBlocks();
return true;
}
@@ -146,38 +113,40 @@ public class TileCKeyStone extends TileEntity {
}
private boolean setKey(ItemStack key) {
if (keyCode == 0 && ItemNBTHelper.getInteger(key, "KeyCode", 0) == 0) {
keyCode = worldObj.rand.nextInt();
ItemNBTHelper.setInteger(key, "KeyCode", keyCode);
ItemNBTHelper.setInteger(key, "X", xCoord);
ItemNBTHelper.setInteger(key, "Y", yCoord);
ItemNBTHelper.setInteger(key, "Z", zCoord);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return true;
} else if (keyCode == 0 && ItemNBTHelper.getInteger(key, "KeyCode", 0) != 0) {
keyCode = ItemNBTHelper.getInteger(key, "KeyCode", 0);
ItemNBTHelper.setInteger(key, "LockCount", ItemNBTHelper.getInteger(key, "LockCount", 0) + 1);
ItemNBTHelper.setInteger(key, "X_" + ItemNBTHelper.getInteger(key, "LockCount", 0), xCoord);
ItemNBTHelper.setInteger(key, "Y_" + ItemNBTHelper.getInteger(key, "LockCount", 0), yCoord);
ItemNBTHelper.setInteger(key, "Z_" + ItemNBTHelper.getInteger(key, "LockCount", 0), zCoord);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return true;
if (keyCode == 0) {
if (ItemNBTHelper.getInteger(key, "KeyCode", 0) == 0) {
keyCode = worldObj.rand.nextInt();
ItemNBTHelper.setInteger(key, "KeyCode", keyCode);
ItemNBTHelper.setInteger(key, "X", xCoord);
ItemNBTHelper.setInteger(key, "Y", yCoord);
ItemNBTHelper.setInteger(key, "Z", zCoord);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return true;
}
if (ItemNBTHelper.getInteger(key, "KeyCode", 0) != 0) {
keyCode = ItemNBTHelper.getInteger(key, "KeyCode", 0);
int lockCount = ItemNBTHelper.getInteger(key, "LockCount", 0) + 1;
ItemNBTHelper.setInteger(key, "LockCount", lockCount);
ItemNBTHelper.setInteger(key, "X_" + lockCount, xCoord);
ItemNBTHelper.setInteger(key, "Y_" + lockCount, yCoord);
ItemNBTHelper.setInteger(key, "Z_" + lockCount, zCoord);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return true;
}
}
return false;
}
private boolean isKeyValid(ItemStack key, EntityPlayer player) {
if (ItemNBTHelper.getInteger(key, "KeyCode", 0) != keyCode) {
if (worldObj.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("msg.wrongKey.txt"));
if (worldObj.isRemote) {
player.addChatComponentMessage(new ChatComponentTranslation("msg.wrongKey.txt"));
}
return false;
}
return true;
}
private int getMeta() {
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
}
public int getKeyCode() {
return keyCode;
}
@@ -212,12 +181,6 @@ public class TileCKeyStone extends TileEntity {
public void updateBlocks() {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord - 1, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 1, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
}
}
@@ -23,138 +23,143 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
public boolean particles_enabled = true;
public static final int MAXIMUM_PARTICLE_INDEX = 3;
public boolean isParticlesEnabled = true;
public int red = 0;
public int green = 0;
public int blue = 0;
public int random_red = 0;
public int random_green = 0;
public int random_blue = 0;
public float motion_x = 0.0F;
public float motion_y = 0.0F;
public float motion_z = 0.0F;
public float random_motion_x = 0.0F;
public float random_motion_y = 0.0F;
public float random_motion_z = 0.0F;
public int randomRed = 0;
public int randomGreen = 0;
public int randomBlue = 0;
public float motionX = 0.0F;
public float motionY = 0.0F;
public float motionZ = 0.0F;
public float randomMotionX = 0.0F;
public float randomMotionY = 0.0F;
public float randomMotionZ = 0.0F;
public float scale = 1F;
public float random_scale = 0F;
public float randomScale = 0F;
public int life = 100;
public int random_life = 0;
public float spawn_x = 0;
public float spawn_y = 0;
public float spawn_z = 0;
public float random_spawn_x = 0;
public float random_spawn_y = 0;
public float random_spawn_z = 0;
public int randomLife = 0;
public float spawnX = 0;
public float spawnY = 0;
public float spawnZ = 0;
public float randomSpawnX = 0;
public float randomSpawnY = 0;
public float randomSpawnZ = 0;
public int page = 1;
public int fade = 0;
public int spawn_rate = 1;
public boolean collide = false;
public int selected_particle = 1;
public int selected_max = 3;
public int spawnRate = 1;
public boolean canParticleCollide = false;
public int selectedParticle = 1;
public float gravity = 0F;
public boolean active = true;
public boolean signal = false;
public boolean inverted = false;
public boolean isActive = true;
public boolean hasRedstoneSignal = false;
public boolean isInverted = false;
TileLocation master = new TileLocation();
public float rotation = 0;
public boolean stabalizerMode = false;
public boolean isInStabilizerMode = false;
// beam
public boolean beam_enabled = false;
public boolean render_core = false;
public boolean isBeamEnabled = false;
public boolean shouldRenderCore = false;
public int beam_red = 0;
public int beam_green = 0;
public int beam_blue = 0;
public float beam_scale = 1F;
public float beam_pitch = 0F;
public float beam_yaw = 0F;
public float beam_length = 0F;
public float beam_rotation = 0F;
public int beamRed = 0;
public int beamGreen = 0;
public int beamBlue = 0;
public float beamScale = 1F;
public float beamPitch = 0F;
public float beamYaw = 0F;
public float beamLength = 0F;
public float beamRotation = 0F;
private int tick = 0;
@SideOnly(Side.SERVER)
@Override
@SideOnly(Side.SERVER)
public boolean canUpdate() {
return false;
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void updateEntity() {
if (!worldObj.isRemote) return;
rotation += 0.5F;
if (stabalizerMode) {
spawnStabilizerParticle();
if (!worldObj.isRemote) {
return;
}
rotation += 0.5F;
if (isInStabilizerMode) {
spawnStabilizerParticle();
return;
}
if (stabalizerMode) return;
if (signal && !inverted) active = true;
else if (!signal && inverted) active = true;
else active = false;
isActive = hasRedstoneSignal != isInverted;
if (tick >= spawn_rate && active && particles_enabled) {
tick = 0;
if (tick < spawnRate || !isActive || !isParticlesEnabled) {
tick++;
return;
}
Random rand = worldObj.rand;
tick = 0;
Random rand = worldObj.rand;
float MX = motion_x + (random_motion_x * rand.nextFloat());
float MY = motion_y + (random_motion_y * rand.nextFloat());
float MZ = motion_z + (random_motion_z * rand.nextFloat());
float SCALE = scale + (random_scale * rand.nextFloat());
double spawnX = xCoord + spawn_x + (random_spawn_x * rand.nextFloat());
double spawnY = yCoord + spawn_y + (random_spawn_y * rand.nextFloat());
double spawnZ = zCoord + spawn_z + (random_spawn_z * rand.nextFloat());
float motionX = this.motionX + (randomMotionX * rand.nextFloat());
float motionY = this.motionY + (randomMotionY * rand.nextFloat());
float motionZ = this.motionZ + (randomMotionZ * rand.nextFloat());
float scale = this.scale + (randomScale * rand.nextFloat());
double spawnX = xCoord + this.spawnX + (randomSpawnX * rand.nextFloat());
double spawnY = yCoord + this.spawnY + (randomSpawnY * rand.nextFloat());
double spawnZ = zCoord + this.spawnZ + (randomSpawnZ * rand.nextFloat());
ParticleCustom particle = new ParticleCustom(
worldObj,
spawnX + 0.5,
spawnY + 0.5,
spawnZ + 0.5,
MX,
MY,
MZ,
SCALE,
collide,
this.selected_particle);
particle.red = this.red + rand.nextInt(random_red + 1);
particle.green = this.green + rand.nextInt(random_green + 1);
particle.blue = this.blue + rand.nextInt(random_blue + 1);
particle.maxAge = this.life + rand.nextInt(random_life + 1);
particle.fadeTime = this.fade;
particle.fadeLength = this.fade;
particle.gravity = this.gravity;
ParticleCustom particle = new ParticleCustom(
worldObj,
spawnX + 0.5,
spawnY + 0.5,
spawnZ + 0.5,
motionX,
motionY,
motionZ,
scale,
canParticleCollide,
this.selectedParticle);
particle.red = this.red + rand.nextInt(randomRed + 1);
particle.green = this.green + rand.nextInt(randomGreen + 1);
particle.blue = this.blue + rand.nextInt(randomBlue + 1);
particle.maxAge = this.life + rand.nextInt(randomLife + 1);
particle.fadeTime = this.fade;
particle.fadeLength = this.fade;
particle.gravity = this.gravity;
ParticleHandler.spawnCustomParticle(particle, 256);
ParticleHandler.spawnCustomParticle(particle, 256);
} else tick++;
}
@SideOnly(Side.CLIENT)
private void spawnStabilizerParticle() {
if (getMaster() == null || worldObj.getTotalWorldTime() % (20) != 1) return;
TileEnergyStorageCore core = getMaster();
if (core == null || worldObj.getTotalWorldTime() % 20 != 1) {
return;
}
double x = xCoord + 0.5;
double y = yCoord + 0.5;
double z = zCoord + 0.5;
int direction = 0;
int direction;
if (getMaster().xCoord > xCoord) direction = 0;
else if (getMaster().xCoord < xCoord) direction = 1;
else if (getMaster().zCoord > zCoord) direction = 2;
else if (getMaster().zCoord < zCoord) direction = 3;
if (core.xCoord != xCoord) {
direction = core.xCoord > xCoord ? 0 : 1;
} else {
direction = core.zCoord > zCoord ? 2 : 3;
}
Particles.EnergyBeamParticle particle = new Particles.EnergyBeamParticle(
worldObj,
x,
y,
z,
getMaster().xCoord + 0.5,
getMaster().zCoord + 0.5,
core.xCoord + 0.5,
core.zCoord + 0.5,
direction,
false);
Particles.EnergyBeamParticle particle2 = new Particles.EnergyBeamParticle(
@@ -162,8 +167,8 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
x,
y,
z,
getMaster().xCoord + 0.5,
getMaster().zCoord + 0.5,
core.xCoord + 0.5,
core.zCoord + 0.5,
direction,
true);
ParticleHandler.spawnCustomParticle(particle, 60);
@@ -171,7 +176,7 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
}
public void toggleInverted() {
inverted = !inverted;
isInverted = !isInverted;
}
@Override
@@ -190,7 +195,7 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
@Override
public void writeToNBT(NBTTagCompound compound) {
master.writeToNBT(compound, "Key");
compound.setBoolean("StabalizerMode", stabalizerMode);
compound.setBoolean("StabalizerMode", isInStabilizerMode);
getBlockNBT(compound);
super.writeToNBT(compound);
@@ -199,27 +204,18 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
@Override
public void readFromNBT(NBTTagCompound compound) {
master.readFromNBT(compound, "Key");
stabalizerMode = compound.getBoolean("StabalizerMode");
isInStabilizerMode = compound.getBoolean("StabalizerMode");
setBlockNBT(compound);
super.readFromNBT(compound);
}
public TileEnergyStorageCore getMaster() {
if (master == null) return null;
TileEnergyStorageCore tile = (worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord())
!= null
&& worldObj.getTileEntity(
master.getXCoord(),
master.getYCoord(),
master.getZCoord()) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) worldObj
.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord())
: null;
return tile;
TileEntity tile = master.getTileEntity(worldObj);
return tile instanceof TileEnergyStorageCore core ? core : null;
}
public void setMaster(TileLocation master) {
this.master = master;
this.master = master != null ? master : new TileLocation();
}
@Override
@@ -231,92 +227,92 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
compound.setInteger("Red", red);
compound.setInteger("Green", green);
compound.setInteger("Blue", blue);
compound.setInteger("RandomRed", random_red);
compound.setInteger("RandomGreen", random_green);
compound.setInteger("RandomBlue", random_blue);
compound.setFloat("MotionX", motion_x);
compound.setFloat("MotionY", motion_y);
compound.setFloat("MotionZ", motion_z);
compound.setFloat("RandomMotionX", random_motion_x);
compound.setFloat("RandomMotionY", random_motion_y);
compound.setFloat("RandomMotionZ", random_motion_z);
compound.setInteger("RandomRed", randomRed);
compound.setInteger("RandomGreen", randomGreen);
compound.setInteger("RandomBlue", randomBlue);
compound.setFloat("MotionX", motionX);
compound.setFloat("MotionY", motionY);
compound.setFloat("MotionZ", motionZ);
compound.setFloat("RandomMotionX", randomMotionX);
compound.setFloat("RandomMotionY", randomMotionY);
compound.setFloat("RandomMotionZ", randomMotionZ);
compound.setFloat("Scale", scale);
compound.setFloat("RandomScale", random_scale);
compound.setFloat("RandomScale", randomScale);
compound.setInteger("Life", life);
compound.setInteger("RandomLife", random_life);
compound.setFloat("SpawnX", spawn_x);
compound.setFloat("SpawnY", spawn_y);
compound.setFloat("SpawnZ", spawn_z);
compound.setFloat("RandomSpawnX", random_spawn_x);
compound.setFloat("RandomSpawnY", random_spawn_y);
compound.setFloat("RandomSpawnZ", random_spawn_z);
compound.setInteger("RandomLife", randomLife);
compound.setFloat("SpawnX", spawnX);
compound.setFloat("SpawnY", spawnY);
compound.setFloat("SpawnZ", spawnZ);
compound.setFloat("RandomSpawnX", randomSpawnX);
compound.setFloat("RandomSpawnY", randomSpawnY);
compound.setFloat("RandomSpawnZ", randomSpawnZ);
compound.setInteger("Page", page);
compound.setInteger("SpawnRate", spawn_rate);
compound.setBoolean("CanCollide", collide);
compound.setInteger("SpawnRate", spawnRate);
compound.setBoolean("CanCollide", canParticleCollide);
compound.setInteger("Fade", fade);
compound.setInteger("SelectedParticle", selected_particle);
compound.setInteger("SelectedParticle", selectedParticle);
compound.setFloat("Gravity", gravity);
compound.setBoolean("Active", active);
compound.setBoolean("Signal", signal);
compound.setBoolean("Inverted", inverted);
compound.setBoolean("particles_enabled", particles_enabled);
compound.setBoolean("Active", isActive);
compound.setBoolean("Signal", hasRedstoneSignal);
compound.setBoolean("Inverted", isInverted);
compound.setBoolean("particles_enabled", isParticlesEnabled);
compound.setBoolean("beam_enabled", beam_enabled);
compound.setBoolean("render_core", render_core);
compound.setInteger("beam_red", beam_red);
compound.setInteger("beam_green", beam_green);
compound.setInteger("beam_blue", beam_blue);
compound.setFloat("beam_scale", beam_scale);
compound.setFloat("beam_pitch", beam_pitch);
compound.setFloat("beam_yaw", beam_yaw);
compound.setFloat("beam_length", beam_length);
compound.setFloat("beam_rotation", beam_rotation);
compound.setBoolean("beam_enabled", isBeamEnabled);
compound.setBoolean("render_core", shouldRenderCore);
compound.setInteger("beam_red", beamRed);
compound.setInteger("beam_green", beamGreen);
compound.setInteger("beam_blue", beamBlue);
compound.setFloat("beam_scale", beamScale);
compound.setFloat("beam_pitch", beamPitch);
compound.setFloat("beam_yaw", beamYaw);
compound.setFloat("beam_length", beamLength);
compound.setFloat("beam_rotation", beamRotation);
}
public void setBlockNBT(NBTTagCompound compound) {
red = compound.getInteger("Red");
green = compound.getInteger("Green");
blue = compound.getInteger("Blue");
random_red = compound.getInteger("RandomRed");
random_green = compound.getInteger("RandomGreen");
random_blue = compound.getInteger("RandomBlue");
motion_x = compound.getFloat("MotionX");
motion_y = compound.getFloat("MotionY");
motion_z = compound.getFloat("MotionZ");
random_motion_x = compound.getFloat("RandomMotionX");
random_motion_y = compound.getFloat("RandomMotionY");
random_motion_z = compound.getFloat("RandomMotionZ");
randomRed = compound.getInteger("RandomRed");
randomGreen = compound.getInteger("RandomGreen");
randomBlue = compound.getInteger("RandomBlue");
motionX = compound.getFloat("MotionX");
motionY = compound.getFloat("MotionY");
motionZ = compound.getFloat("MotionZ");
randomMotionX = compound.getFloat("RandomMotionX");
randomMotionY = compound.getFloat("RandomMotionY");
randomMotionZ = compound.getFloat("RandomMotionZ");
scale = compound.getFloat("Scale");
random_scale = compound.getFloat("RandomScale");
randomScale = compound.getFloat("RandomScale");
life = compound.getInteger("Life");
random_life = compound.getInteger("RandomLife");
spawn_x = compound.getFloat("SpawnX");
spawn_y = compound.getFloat("SpawnY");
spawn_z = compound.getFloat("SpawnZ");
random_spawn_x = compound.getFloat("RandomSpawnX");
random_spawn_y = compound.getFloat("RandomSpawnY");
random_spawn_z = compound.getFloat("RandomSpawnZ");
randomLife = compound.getInteger("RandomLife");
spawnX = compound.getFloat("SpawnX");
spawnY = compound.getFloat("SpawnY");
spawnZ = compound.getFloat("SpawnZ");
randomSpawnX = compound.getFloat("RandomSpawnX");
randomSpawnY = compound.getFloat("RandomSpawnY");
randomSpawnZ = compound.getFloat("RandomSpawnZ");
page = compound.getInteger("Page");
spawn_rate = compound.getInteger("SpawnRate");
collide = compound.getBoolean("CanCollide");
spawnRate = compound.getInteger("SpawnRate");
canParticleCollide = compound.getBoolean("CanCollide");
fade = compound.getInteger("Fade");
selected_particle = compound.getInteger("SelectedParticle");
selectedParticle = compound.getInteger("SelectedParticle");
gravity = compound.getFloat("Gravity");
active = compound.getBoolean("Active");
signal = compound.getBoolean("Signal");
inverted = compound.getBoolean("Inverted");
particles_enabled = compound.getBoolean("particles_enabled");
isActive = compound.getBoolean("Active");
hasRedstoneSignal = compound.getBoolean("Signal");
isInverted = compound.getBoolean("Inverted");
isParticlesEnabled = compound.getBoolean("particles_enabled");
beam_enabled = compound.getBoolean("beam_enabled");
render_core = compound.getBoolean("render_core");
beam_red = compound.getInteger("beam_red");
beam_green = compound.getInteger("beam_green");
beam_blue = compound.getInteger("beam_blue");
beam_scale = compound.getFloat("beam_scale");
beam_pitch = compound.getFloat("beam_pitch");
beam_yaw = compound.getFloat("beam_yaw");
beam_length = compound.getFloat("beam_length");
beam_rotation = compound.getFloat("beam_rotation");
isBeamEnabled = compound.getBoolean("beam_enabled");
shouldRenderCore = compound.getBoolean("render_core");
beamRed = compound.getInteger("beam_red");
beamGreen = compound.getInteger("beam_green");
beamBlue = compound.getInteger("beam_blue");
beamScale = compound.getFloat("beam_scale");
beamPitch = compound.getFloat("beam_pitch");
beamYaw = compound.getFloat("beam_yaw");
beamLength = compound.getFloat("beam_length");
beamRotation = compound.getFloat("beam_rotation");
}
@SideOnly(Side.CLIENT)
@@ -345,12 +341,15 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
@Override
public Object[] callMethod(String method, Object... args) {
if (method.startsWith("setGeneratorProperty")) {
if (args.length != 2) return new Object[] { false };
else if (!(args[0] instanceof String)) return new Object[] { false };
if (args.length != 2) {
return new Object[] { false };
} else if (!(args[0] instanceof String)) {
return new Object[] { false };
}
/* Particles */
if (args[0].equals("particles_enabled") && args[1] instanceof Boolean) {
particles_enabled = (Boolean) args[1];
isParticlesEnabled = (boolean) args[1];
} else if (args[0].equals("red") && args[1] instanceof Double) {
red = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("green") && args[1] instanceof Double) {
@@ -358,75 +357,75 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
} else if (args[0].equals("blue") && args[1] instanceof Double) {
blue = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("random_red") && args[1] instanceof Double) {
random_red = limit(((Double) args[1]).intValue(), 0, 255);
randomRed = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("random_green") && args[1] instanceof Double) {
random_green = limit(((Double) args[1]).intValue(), 0, 255);
randomGreen = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("random_blue") && args[1] instanceof Double) {
random_blue = limit(((Double) args[1]).intValue(), 0, 255);
randomBlue = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("motion_x") && args[1] instanceof Double) {
motion_x = (float) limit((Double) args[1], -5F, 5F);
motionX = (float) limit((Double) args[1], -5F, 5F);
} else if (args[0].equals("motion_y") && args[1] instanceof Double) {
motion_y = (float) limit((Double) args[1], -5F, 5F);
motionY = (float) limit((Double) args[1], -5F, 5F);
} else if (args[0].equals("motion_z") && args[1] instanceof Double) {
motion_z = (float) limit((Double) args[1], -5F, 5F);
motionZ = (float) limit((Double) args[1], -5F, 5F);
} else if (args[0].equals("random_motion_x") && args[1] instanceof Double) {
random_motion_x = (float) limit((Double) args[1], -5F, 5F);
randomMotionX = (float) limit((Double) args[1], -5F, 5F);
} else if (args[0].equals("random_motion_y") && args[1] instanceof Double) {
random_motion_y = (float) limit((Double) args[1], -5F, 5F);
randomMotionY = (float) limit((Double) args[1], -5F, 5F);
} else if (args[0].equals("random_motion_z") && args[1] instanceof Double) {
random_motion_z = (float) limit((Double) args[1], -5F, 5F);
randomMotionZ = (float) limit((Double) args[1], -5F, 5F);
} else if (args[0].equals("scale") && args[1] instanceof Double) {
scale = (float) limit((Double) args[1], 0.01F, 50F);
} else if (args[0].equals("random_scale") && args[1] instanceof Double) {
random_scale = (float) limit((Double) args[1], 0.01F, 50F);
randomScale = (float) limit((Double) args[1], 0.01F, 50F);
} else if (args[0].equals("life") && args[1] instanceof Double) {
life = limit(((Double) args[1]).intValue(), 0, 1000);
} else if (args[0].equals("random_life") && args[1] instanceof Double) {
random_life = limit(((Double) args[1]).intValue(), 0, 1000);
randomLife = limit(((Double) args[1]).intValue(), 0, 1000);
} else if (args[0].equals("spawn_x") && args[1] instanceof Double) {
spawn_x = (float) limit((Double) args[1], -50F, 50F);
spawnX = (float) limit((Double) args[1], -50F, 50F);
} else if (args[0].equals("spawn_y") && args[1] instanceof Double) {
spawn_y = (float) limit((Double) args[1], -50F, 50F);
spawnY = (float) limit((Double) args[1], -50F, 50F);
} else if (args[0].equals("spawn_z") && args[1] instanceof Double) {
spawn_z = (float) limit((Double) args[1], -50F, 50F);
spawnZ = (float) limit((Double) args[1], -50F, 50F);
} else if (args[0].equals("random_spawn_x") && args[1] instanceof Double) {
random_spawn_x = (float) limit((Double) args[1], -50F, 50F);
randomSpawnX = (float) limit((Double) args[1], -50F, 50F);
} else if (args[0].equals("random_spawn_y") && args[1] instanceof Double) {
random_spawn_y = (float) limit((Double) args[1], -50F, 50F);
randomSpawnY = (float) limit((Double) args[1], -50F, 50F);
} else if (args[0].equals("random_spawn_z") && args[1] instanceof Double) {
random_spawn_z = (float) limit((Double) args[1], -50F, 50F);
randomSpawnZ = (float) limit((Double) args[1], -50F, 50F);
} else if (args[0].equals("fade") && args[1] instanceof Double) {
fade = limit(((Double) args[1]).intValue(), 0, 100);
} else if (args[0].equals("spawn_rate") && args[1] instanceof Double) {
spawn_rate = limit(((Double) args[1]).intValue(), 1, 200);
} else if (args[0].equals("collide") && args[1] instanceof Double) {
collide = (Boolean) args[1];
spawnRate = limit(((Double) args[1]).intValue(), 1, 200);
} else if (args[0].equals("collide") && args[1] instanceof Boolean) {
canParticleCollide = (Boolean) args[1];
} else if (args[0].equals("selected_particle") && args[1] instanceof Double) {
selected_particle = limit(((Double) args[1]).intValue(), 1, selected_max);
selectedParticle = limit(((Double) args[1]).intValue(), 1, MAXIMUM_PARTICLE_INDEX);
} else if (args[0].equals("gravity") && args[1] instanceof Double) {
gravity = (float) limit((Double) args[1], -5F, 5F);
}
/* Beam */
else if (args[0].equals("beam_enabled") && args[1] instanceof Boolean) {
beam_enabled = (Boolean) args[1];
isBeamEnabled = (Boolean) args[1];
} else if (args[0].equals("render_core") && args[1] instanceof Boolean) {
render_core = (Boolean) args[1];
shouldRenderCore = (Boolean) args[1];
} else if (args[0].equals("beam_red") && args[1] instanceof Double) {
beam_red = limit(((Double) args[1]).intValue(), 0, 255);
beamRed = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("beam_green") && args[1] instanceof Double) {
beam_green = limit(((Double) args[1]).intValue(), 0, 255);
beamGreen = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("beam_blue") && args[1] instanceof Double) {
beam_blue = limit(((Double) args[1]).intValue(), 0, 255);
beamBlue = limit(((Double) args[1]).intValue(), 0, 255);
} else if (args[0].equals("beam_scale") && args[1] instanceof Double) {
beam_scale = (float) limit((Double) args[1], -0F, 5F);
beamScale = (float) limit((Double) args[1], -0F, 5F);
} else if (args[0].equals("beam_pitch") && args[1] instanceof Double) {
beam_pitch = (float) limit((Double) args[1], -180F, 180F);
beamPitch = (float) limit((Double) args[1], -180F, 180F);
} else if (args[0].equals("beam_yaw") && args[1] instanceof Double) {
beam_yaw = (float) limit((Double) args[1], -180F, 180F);
beamYaw = (float) limit((Double) args[1], -180F, 180F);
} else if (args[0].equals("beam_length") && args[1] instanceof Double) {
beam_length = (float) limit((Double) args[1], -0F, 320F);
beamLength = (float) limit((Double) args[1], -0F, 320F);
} else if (args[0].equals("beam_rotation") && args[1] instanceof Double) {
beam_rotation = (float) limit((Double) args[1], -1F, 1F);
beamRotation = (float) limit((Double) args[1], -1F, 1F);
} else {
return new Object[] { false };
}
@@ -434,94 +433,94 @@ public class TileParticleGenerator extends TileEntity implements IDEPeripheral {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return new Object[] { true };
} else if (method.startsWith("getGeneratorState")) {
Map<Object, Object> map = new HashMap<Object, Object>();
Map<Object, Object> map = new HashMap<>();
/* Particles */
map.put("particles_enabled", particles_enabled);
map.put("particles_enabled", isParticlesEnabled);
map.put("red", red);
map.put("green", green);
map.put("blue", blue);
map.put("random_red", random_red);
map.put("random_green", random_green);
map.put("random_blue", random_blue);
map.put("motion_x", motion_x);
map.put("motion_y", motion_y);
map.put("motion_z", motion_z);
map.put("random_motion_x", random_motion_x);
map.put("random_motion_y", random_motion_y);
map.put("random_motion_z", random_motion_z);
map.put("random_red", randomRed);
map.put("random_green", randomGreen);
map.put("random_blue", randomBlue);
map.put("motion_x", motionX);
map.put("motion_y", motionY);
map.put("motion_z", motionZ);
map.put("random_motion_x", randomMotionX);
map.put("random_motion_y", randomMotionY);
map.put("random_motion_z", randomMotionZ);
map.put("scale", scale);
map.put("random_scale", random_scale);
map.put("random_scale", randomScale);
map.put("life", life);
map.put("random_life", random_life);
map.put("spawn_x", spawn_x);
map.put("spawn_y", spawn_y);
map.put("spawn_z", spawn_z);
map.put("random_spawn_x", random_spawn_x);
map.put("random_spawn_y", random_spawn_y);
map.put("random_spawn_z", random_spawn_z);
map.put("random_life", randomLife);
map.put("spawn_x", spawnX);
map.put("spawn_y", spawnY);
map.put("spawn_z", spawnZ);
map.put("random_spawn_x", randomSpawnX);
map.put("random_spawn_y", randomSpawnY);
map.put("random_spawn_z", randomSpawnZ);
map.put("fade", fade);
map.put("spawn_rate", spawn_rate);
map.put("collide", collide);
map.put("selected_particle", selected_particle);
map.put("spawn_rate", spawnRate);
map.put("collide", canParticleCollide);
map.put("selected_particle", selectedParticle);
map.put("gravity", gravity);
/* Beam */
map.put("beam_enabled", beam_enabled);
map.put("render_core", render_core);
map.put("beam_red", beam_red);
map.put("beam_green", beam_green);
map.put("beam_blue", beam_blue);
map.put("beam_scale", beam_scale);
map.put("beam_pitch", beam_pitch);
map.put("beam_yaw", beam_yaw);
map.put("beam_length", beam_length);
map.put("beam_rotation", beam_rotation);
map.put("beam_enabled", isBeamEnabled);
map.put("render_core", shouldRenderCore);
map.put("beam_red", beamRed);
map.put("beam_green", beamGreen);
map.put("beam_blue", beamBlue);
map.put("beam_scale", beamScale);
map.put("beam_pitch", beamPitch);
map.put("beam_yaw", beamYaw);
map.put("beam_length", beamLength);
map.put("beam_rotation", beamRotation);
return new Object[] { map };
} else if (method.startsWith("resetGeneratorState")) {
particles_enabled = true;
isParticlesEnabled = true;
red = 0;
green = 0;
blue = 0;
random_red = 0;
random_green = 0;
random_blue = 0;
motion_x = 0.0F;
motion_y = 0.0F;
motion_z = 0.0F;
random_motion_x = 0.0F;
random_motion_y = 0.0F;
random_motion_z = 0.0F;
randomRed = 0;
randomGreen = 0;
randomBlue = 0;
motionX = 0.0F;
motionY = 0.0F;
motionZ = 0.0F;
randomMotionX = 0.0F;
randomMotionY = 0.0F;
randomMotionZ = 0.0F;
scale = 1F;
random_scale = 0F;
randomScale = 0F;
life = 100;
random_life = 0;
spawn_x = 0;
spawn_y = 0;
spawn_z = 0;
random_spawn_x = 0;
random_spawn_y = 0;
random_spawn_z = 0;
randomLife = 0;
spawnX = 0;
spawnY = 0;
spawnZ = 0;
randomSpawnX = 0;
randomSpawnY = 0;
randomSpawnZ = 0;
page = 1;
fade = 0;
spawn_rate = 1;
collide = false;
selected_particle = 1;
spawnRate = 1;
canParticleCollide = false;
selectedParticle = 1;
gravity = 0F;
// beam
beam_enabled = false;
render_core = false;
isBeamEnabled = false;
shouldRenderCore = false;
beam_red = 0;
beam_green = 0;
beam_blue = 0;
beam_scale = 1F;
beam_pitch = 0F;
beam_yaw = 0F;
beam_length = 0F;
beam_rotation = 0F;
beamRed = 0;
beamGreen = 0;
beamBlue = 0;
beamScale = 1F;
beamPitch = 0F;
beamYaw = 0F;
beamLength = 0F;
beamRotation = 0F;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return new Object[] { true };
@@ -6,53 +6,75 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TilePlayerDetector extends TileEntity {
public static final int MAXIMUM_RANGE = 10;
public static final int MINIMUM_RANGE = 1;
private static final int scanRate = 5;
private int tick = 0;
public boolean output = false;
private int scanRate = 5;
private boolean shouldOutput = false;
private int range = 1;
@Override
public void updateEntity() {
if (worldObj.isRemote) return;
if (worldObj.isRemote) {
return;
}
if (tick >= scanRate) {
tick = 0;
EntityPlayer player = worldObj.getClosestPlayer(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, range + 0.5D);
if (player != null) {
if (!output) setOutput(true);
if (!shouldOutput) setShouldOutput(true);
} else {
if (output) setOutput(false);
if (shouldOutput) setShouldOutput(false);
}
} else tick++;
} else {
tick++;
}
}
private void setOutput(boolean out) {
output = out;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
public boolean shouldOutput() {
return shouldOutput;
}
public void setShouldOutput(boolean shouldOutputSignal) {
shouldOutput = shouldOutputSignal;
updateBlocks();
}
public void setRange(int value) {
this.range = value;
}
public int getRange() {
return range;
}
public void updateBlocks() {
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord - 1, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 1, worldObj.getBlock(xCoord, yCoord, zCoord));
public void setRange(int value) {
if (value > MAXIMUM_RANGE) {
value = MINIMUM_RANGE;
}
if (value < MINIMUM_RANGE) {
value = MAXIMUM_RANGE;
}
this.range = value;
updateBlocks();
}
private void updateBlocks() {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
worldObj.notifyBlocksOfNeighborChange(
xCoord + direction.offsetX,
yCoord + direction.offsetY,
zCoord + direction.offsetZ,
blockType,
direction.getOpposite().ordinal());
}
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tagCompound = new NBTTagCompound();
this.writeToNBT(tagCompound);
@@ -62,22 +84,19 @@ public class TilePlayerDetector extends TileEntity {
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public void writeToNBT(NBTTagCompound compound) {
compound.setBoolean("OutPut", output);
compound.setBoolean("OutPut", shouldOutput);
compound.setInteger("Range", range);
super.writeToNBT(compound);
}
@Override
public void readFromNBT(NBTTagCompound compound) {
output = compound.getBoolean("OutPut");
shouldOutput = compound.getBoolean("OutPut");
range = compound.getInteger("Range");
super.readFromNBT(compound);
}
}
@@ -1,10 +1,8 @@
package com.brandon3055.draconicevolution.common.tileentities;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@@ -16,101 +14,108 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.draconicevolution.common.container.ContainerPlayerDetector;
public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory {
public static final int MAXIMUM_RANGE = 20;
public static final int MINIMUM_RANGE = 1;
private static final int scanRate = 5;
public String[] names = new String[42];
private ItemStack[] items;
public boolean whiteList = false;
public boolean isInWhiteListMode = false;
public boolean isOutputInverted = false;
public int range = 10;
private final ItemStack[] items;
private int tick = 0;
private int scanRate = 5;
public boolean output = false;
public boolean outputInverted = false;
private List<EntityLiving> EntityList;
private boolean shouldOutput = false;
private List<EntityLivingBase> entityList;
public TilePlayerDetectorAdvanced() {
for (int i = 0; i < names.length; i++) if (names[i] == null) names[i] = "";
for (int i = 0; i < names.length; i++) {
if (names[i] == null) {
names[i] = "";
}
}
items = new ItemStack[1];
}
@Override
public void updateEntity() {
if (worldObj.isRemote) return;
if (worldObj.isRemote) {
return;
}
if (tick >= scanRate) {
tick = 0;
if (shouldEmit()) {
if (!output) setOutput(true);
if (!shouldOutput) setShouldOutput(true);
} else {
if (output) setOutput(false);
}
} else tick++;
}
public boolean shouldEmit() {
findEntitys();
boolean b = false;
Iterator<EntityLiving> i = EntityList.iterator();
while (i.hasNext()) {
Entity ent = i.next();
if (!(ent instanceof EntityPlayer)) return false;
String name = ((EntityPlayer) ent).getCommandSenderName();
if (whiteList) {
if (isPlayerListed(name)) return true;
} else {
if (!isPlayerListed(name)) return true;
if (shouldOutput) setShouldOutput(false);
}
} else {
tick++;
}
return b;
}
private void findEntitys() {
double x1 = xCoord + 0.5 - range;
double y1 = yCoord + 0.5 - range;
double z1 = zCoord + 0.5 - range;
double x2 = xCoord + 0.5 + range;
double y2 = yCoord + 0.5 + range;
double z2 = zCoord + 0.5 + range;
private boolean shouldEmit() {
findEntities();
// System.out.println(x1 + " " + y1 + " " + z1 + " " + x2 + " " + y2 + " " + z2);
// ScanBox = AxisAlignedBB.getBoundingBox(x1, y1, z1, x2, y2, z2);
// ScanBox = AxisAlignedBB.getAABBPool().getAABB(xCoord + 0.5 - range, yCoord + 0.5 - range, zCoord + 0.5 -
// range, xCoord + 0.5 + range, yCoord + 0.5 + range, zCoord + 0.5 + range);
EntityList = worldObj
.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x1, y1, z1, x2, y2, z2));
// System.out.println(EntityList);
for (EntityLivingBase entity : entityList) {
if (!(entity instanceof EntityPlayer)) {
return false;
}
String name = entity.getCommandSenderName();
return (isInWhiteListMode == isPlayerListed(name)) != isOutputInverted;
}
return isOutputInverted;
}
private void setOutput(boolean out) {
output = out;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
private void findEntities() {
double startX = xCoord + 0.5 - range;
double startY = yCoord + 0.5 - range;
double startZ = zCoord + 0.5 - range;
double endX = xCoord + 0.5 + range;
double endY = yCoord + 0.5 + range;
double endZ = zCoord + 0.5 + range;
entityList = worldObj.getEntitiesWithinAABB(
EntityPlayer.class,
AxisAlignedBB.getBoundingBox(startX, startY, startZ, endX, endY, endZ));
}
public boolean shouldOutput() {
return shouldOutput;
}
public void setShouldOutput(boolean shouldOutputSignal) {
shouldOutput = shouldOutputSignal;
updateBlocks();
}
public void updateBlocks() {
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord - 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord + 1, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord + 1, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord - 1, worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord + 1, worldObj.getBlock(xCoord, yCoord, zCoord));
private void updateBlocks() {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
worldObj.notifyBlocksOfNeighborChange(
xCoord + direction.offsetX,
yCoord + direction.offsetY,
zCoord + direction.offsetZ,
blockType,
direction.getOpposite().ordinal());
}
}
public boolean isPlayerListed(String name) {
if (name == null) return false;
private boolean isPlayerListed(String name) {
if (name == null) {
return false;
}
for (int i = 0; i < names.length; i++) {
if (names[i].equals(name)) return true;
for (String listedName : names) {
if (listedName.equals(name)) {
return true;
}
}
return false;
}
@@ -121,39 +126,40 @@ public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory
}
@Override
public ItemStack getStackInSlot(int i) {
return items[i];
public ItemStack getStackInSlot(int slot) {
return items[slot];
}
@Override
public ItemStack decrStackSize(int i, int count) {
ItemStack itemstack = getStackInSlot(i);
if (itemstack != null) {
if (itemstack.stackSize <= count) {
setInventorySlotContents(i, null);
public ItemStack decrStackSize(int slot, int count) {
ItemStack stack = items[slot];
if (stack != null) {
if (stack.stackSize <= count) {
setInventorySlotContents(slot, null);
} else {
itemstack = itemstack.splitStack(count);
if (itemstack.stackSize == 0) {
setInventorySlotContents(i, null);
stack = stack.splitStack(count);
if (stack.stackSize == 0) {
setInventorySlotContents(slot, null);
}
}
}
return itemstack;
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
ItemStack item = getStackInSlot(i);
if (item != null) setInventorySlotContents(i, null);
return item;
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
setInventorySlotContents(slot, null);
}
return stack;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
items[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
itemstack.stackSize = getInventoryStackLimit();
public void setInventorySlotContents(int slot, ItemStack stack) {
items[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@@ -191,7 +197,7 @@ public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return false;
}
@@ -206,11 +212,10 @@ public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
public Container getGuiContainer(InventoryPlayer inventoryplayer) {
return new ContainerPlayerDetector(inventoryplayer, this);
public Container getGuiContainer(InventoryPlayer playerInventory) {
return new ContainerPlayerDetector(playerInventory, this);
}
@Override
@@ -232,10 +237,10 @@ public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory
compound.setString("Name_" + i, name);
}
compound.setBoolean("WhiteList", whiteList);
compound.setBoolean("Output", output);
compound.setBoolean("WhiteList", isInWhiteListMode);
compound.setBoolean("Output", shouldOutput);
compound.setInteger("Range", range);
compound.setBoolean("OutputInverted", outputInverted);
compound.setBoolean("OutputInverted", isOutputInverted);
super.writeToNBT(compound);
}
@@ -251,10 +256,10 @@ public class TilePlayerDetectorAdvanced extends TileEntity implements IInventory
for (int i = 0; i < names.length; i++) names[i] = compound.getString("Name_" + i);
whiteList = compound.getBoolean("WhiteList");
isInWhiteListMode = compound.getBoolean("WhiteList");
range = compound.getInteger("Range");
output = compound.getBoolean("Output");
outputInverted = compound.getBoolean("OutputInverted");
shouldOutput = compound.getBoolean("Output");
isOutputInverted = compound.getBoolean("OutputInverted");
super.readFromNBT(compound);
}
@@ -27,27 +27,37 @@ public class TileDislocatorReceptacle extends TileEntity implements IInventory {
@Override
public void updateEntity() {
if (worldObj.isRemote) return;
if (coolDown > 0) coolDown--;
if (ticksTillStart > -1) ticksTillStart--;
if (ticksTillStart == 0)
if (worldObj.isRemote) {
return;
}
if (coolDown > 0) {
coolDown--;
}
if (ticksTillStart > -1) {
ticksTillStart--;
}
if (ticksTillStart == 0) {
worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord), 1);
}
}
public void validateActivePortal() {
if (updating) return;
if (structure == null) {
isActive = false;
if (updating) {
return;
}
isActive = structure.checkFrameIsValid(worldObj, xCoord, yCoord, zCoord)
final boolean isActiveBeforeValidation = isActive;
isActive = structure != null && structure.checkFrameIsValid(worldObj, xCoord, yCoord, zCoord)
&& structure.scanPortal(worldObj, xCoord, yCoord, zCoord, false, true);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
if (isActive != isActiveBeforeValidation) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
public void updateState() {
if (structure == null || !isActive)
if (structure == null || !isActive) {
structure = PortalHelper.getValidStructure(worldObj, xCoord, yCoord, zCoord);
}
if (structure == null) {
isActive = false;
worldObj.notifyBlockChange(xCoord, yCoord, zCoord, blockType);
@@ -55,25 +65,30 @@ public class TileDislocatorReceptacle extends TileEntity implements IInventory {
return;
}
final boolean isActiveBeforeUpdate = isActive;
if (isActive) {
if (getStackInSlot(0) == null || !structure.checkFrameIsValid(worldObj, xCoord, yCoord, zCoord))
if (dislocator == null || !structure.checkFrameIsValid(worldObj, xCoord, yCoord, zCoord)) {
isActive = false;
}
} else {
boolean frameValid = structure.checkFrameIsValid(worldObj, xCoord, yCoord, zCoord);
boolean portalEmpty = structure.scanPortal(worldObj, xCoord, yCoord, zCoord, false, false);
boolean isFrameValid = structure.checkFrameIsValid(worldObj, xCoord, yCoord, zCoord);
boolean isPortalEmpty = structure.scanPortal(worldObj, xCoord, yCoord, zCoord, false, false);
if (getLocation() != null && frameValid && portalEmpty) {
if (getLocation() != null && isFrameValid && isPortalEmpty) {
isActive = true;
structure.scanPortal(worldObj, xCoord, yCoord, zCoord, true, false);
}
}
worldObj.notifyBlockChange(xCoord, yCoord, zCoord, blockType);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
if (isActive != isActiveBeforeUpdate) {
worldObj.notifyBlockChange(xCoord, yCoord, zCoord, blockType);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
public Teleporter.TeleportLocation getLocation() {
if (getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof TeleporterMKI)
return ((TeleporterMKI) getStackInSlot(0).getItem()).getLocation(getStackInSlot(0));
if (dislocator != null && dislocator.getItem() instanceof TeleporterMKI teleporter) {
return teleporter.getLocation(dislocator);
}
return null;
}
@@ -100,40 +115,40 @@ public class TileDislocatorReceptacle extends TileEntity implements IInventory {
}
@Override
public ItemStack decrStackSize(int i, int count) {
ItemStack itemstack = getStackInSlot(i);
if (itemstack != null) {
if (itemstack.stackSize <= count) {
setInventorySlotContents(i, null);
} else {
itemstack = itemstack.splitStack(count);
if (itemstack.stackSize == 0) {
setInventorySlotContents(i, null);
}
public ItemStack decrStackSize(int index, int count) {
ItemStack stack = null;
if (index == 0 && dislocator != null) {
stack = dislocator;
if (count >= 1) {
setInventorySlotContents(index, null);
}
}
if (isActive) updateState();
else ticksTillStart = 1;
return itemstack;
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
ItemStack item = getStackInSlot(i);
if (item != null) setInventorySlotContents(i, null);
return item;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
if (i != 0) return;
dislocator = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
itemstack.stackSize = getInventoryStackLimit();
public ItemStack getStackInSlotOnClosing(int index) {
ItemStack stack = getStackInSlot(index);
if (stack != null) {
setInventorySlotContents(index, null);
}
return stack;
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (index != 0) {
return;
}
dislocator = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
if (isActive) {
updateState();
} else {
ticksTillStart = 1;
}
if (isActive) updateState();
else ticksTillStart = 1;
}
@Override
@@ -169,9 +184,10 @@ public class TileDislocatorReceptacle extends TileEntity implements IInventory {
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return itemstack != null && itemstack.getItem() instanceof TeleporterMKI
&& ((TeleporterMKI) itemstack.getItem()).getLocation(itemstack) != null;
public boolean isItemValidForSlot(int index, ItemStack stack) {
return index == 0 && stack != null
&& stack.getItem() instanceof TeleporterMKI teleporter
&& teleporter.getLocation(stack) != null;
}
@Override
@@ -14,7 +14,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.draconicevolution.api.IExtendedRFStorage;
import com.brandon3055.draconicevolution.client.handler.ParticleHandler;
import com.brandon3055.draconicevolution.client.render.particle.Particles;
import com.brandon3055.draconicevolution.client.render.particle.Particles.EnergyTransferParticle;
import com.brandon3055.draconicevolution.common.ModBlocks;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation;
import com.brandon3055.draconicevolution.common.lib.References;
@@ -34,11 +34,11 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
public boolean active = false;
public boolean lastTickActive = false;
public boolean reciveEnergy = false; // Power Flow to system
public boolean lastTickReciveEnergy = false;
public boolean isReceivingEnergy = false; // Power Flow to system
public boolean isReceivedEnergyLastTick = false;
public float modelRotation = 0;
public float modelScale = 0;
private List<TileLocation> coreLocatios = new ArrayList<TileLocation>();
private List<TileLocation> coreLocations = new ArrayList<>();
private int selectedCore = 0;
private byte particleRate = 0;
private byte lastTickParticleRate = 0;
@@ -47,68 +47,37 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
@Override
public void updateEntity() {
if (active && worldObj.isRemote) {
modelRotation += 1.5;
modelScale += !reciveEnergy ? -0.01F : 0.01F;
if ((modelScale < 0 && !reciveEnergy)) modelScale = 10000F;
if ((modelScale < 0 && reciveEnergy)) modelScale = 0F;
spawnParticles();
} else if (worldObj.isRemote) modelScale = 0.5F;
if (worldObj.isRemote) return;
if (worldObj.isRemote) {
if (active) {
modelRotation += 1.5;
modelScale += isReceivingEnergy ? 0.01F : -0.01F;
if (modelScale < 0) {
modelScale = isReceivingEnergy ? 0F : 10000F;
}
spawnParticles();
} else {
modelScale = 0.5F;
}
return;
}
tick++;
if (tick % 20 == 0) {
int cOut = (int) (getEnergyStored() / getMaxEnergyStored() * 15D);
if (cOut != lastCheckCompOverride) {
worldObj.notifyBlocksOfNeighborChange(
xCoord,
yCoord,
zCoord,
worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(
xCoord - 1,
yCoord,
zCoord,
worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(
xCoord + 1,
yCoord,
zCoord,
worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(
xCoord,
yCoord - 1,
zCoord,
worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(
xCoord,
yCoord + 1,
zCoord,
worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(
xCoord,
yCoord,
zCoord - 1,
worldObj.getBlock(xCoord, yCoord, zCoord));
worldObj.notifyBlocksOfNeighborChange(
xCoord,
yCoord,
zCoord + 1,
worldObj.getBlock(xCoord, yCoord, zCoord));
lastCheckCompOverride = cOut;
int comparatorOut = (int) (getEnergyStored() / getMaxEnergyStored() * 15D);
if (comparatorOut != lastCheckCompOverride) {
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
lastCheckCompOverride = comparatorOut;
}
}
if (active && !reciveEnergy) {
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = worldObj.getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ);
if (tile != null && tile instanceof IEnergyReceiver) {
extractEnergy(
d,
((IEnergyReceiver) tile)
.receiveEnergy(d.getOpposite(), extractEnergy(d, Integer.MAX_VALUE, true), false),
false);
if (active && !isReceivingEnergy) {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = worldObj
.getTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
if (tile instanceof IEnergyReceiver receiver) {
int energyToReceive = extractEnergy(side, Integer.MAX_VALUE, true);
int energyReceived = receiver.receiveEnergy(side.getOpposite(), energyToReceive, false);
extractEnergy(side, energyReceived, false);
}
}
}
@@ -125,19 +94,22 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
}
private TileEnergyStorageCore getMaster() {
if (coreLocatios.isEmpty()) return null;
if (selectedCore >= coreLocatios.size()) selectedCore = coreLocatios.size() - 1;
TileLocation core = coreLocatios.get(selectedCore);
if (core == null || !(worldObj
.getTileEntity(core.getXCoord(), core.getYCoord(), core.getZCoord()) instanceof TileEnergyStorageCore))
return null;
return (TileEnergyStorageCore) worldObj.getTileEntity(core.getXCoord(), core.getYCoord(), core.getZCoord());
if (coreLocations.isEmpty()) return null;
if (selectedCore >= coreLocations.size()) selectedCore = coreLocations.size() - 1;
TileLocation location = coreLocations.get(selectedCore);
if (location != null) {
TileEntity tile = location.getTileEntity(worldObj);
if (tile instanceof TileEnergyStorageCore core) {
return core;
}
}
return null;
}
private void findCores() {
int yMod = worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1 ? 15 : -15;
int range = 15;
List<TileLocation> locations = new ArrayList<TileLocation>();
List<TileLocation> locations = new ArrayList<>();
for (int x = xCoord - range; x <= xCoord + range; x++) {
for (int y = yCoord + yMod - range; y <= yCoord + yMod + range; y++) {
for (int z = zCoord - range; z <= zCoord + range; z++) {
@@ -148,10 +120,10 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
}
}
if (locations != coreLocatios) {
coreLocatios.clear();
coreLocatios.addAll(locations);
selectedCore = selectedCore >= coreLocatios.size() ? 0 : selectedCore;
if (locations != coreLocations) {
coreLocations.clear();
coreLocations.addAll(locations);
selectedCore = selectedCore >= coreLocations.size() ? 0 : selectedCore;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@@ -159,135 +131,69 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
public void nextCore() {
findCores();
selectedCore++;
if (selectedCore >= coreLocatios.size()) selectedCore = 0;
if (selectedCore >= coreLocations.size()) selectedCore = 0;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@SideOnly(Side.CLIENT)
private void spawnParticles() {
Random rand = worldObj.rand;
if (getMaster() == null || !getMaster().isOnline()) return;
int x = getMaster().xCoord;
int y = getMaster().yCoord;
int z = getMaster().zCoord;
TileEnergyStorageCore core = getMaster();
if (core == null || !core.isOnline()) return;
int x = core.xCoord;
int y = core.yCoord;
int z = core.zCoord;
int cYCoord = worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1 ? yCoord + 1 : yCoord - 1;
float disMod = getMaster().getTier() == 0 ? 0.5F
: getMaster().getTier() == 1 ? 1F
: getMaster().getTier() == 2 ? 1F
: getMaster().getTier() == 3 ? 2F
: getMaster().getTier() == 4 ? 2F : getMaster().getTier() == 5 ? 3F : 4F;
double spawnX;
double spawnY;
double spawnZ;
double targetX;
double targetY;
double targetZ;
float disMod = switch (core.getTier()) {
case 0 -> 0.5F;
case 1, 2 -> 1F;
case 3, 4 -> 2F;
case 5 -> 3F;
default -> 4F;
};
if (particleRate > 20) particleRate = 20;
if (!reciveEnergy) {
spawnX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
spawnY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
spawnZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
targetX = xCoord + 0.5;
targetY = cYCoord + 0.5;
targetZ = zCoord + 0.5;
if (rand.nextFloat() < 0.05F) {
Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(
worldObj,
spawnX,
spawnY,
spawnZ,
targetX,
targetY,
targetZ,
true);
ParticleHandler.spawnCustomParticle(passiveParticle, 35);
}
if (particleRate > 0) {
if (particleRate > 10) {
for (int i = 0; i <= particleRate / 10; i++) {
spawnX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
spawnY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
spawnZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(
worldObj,
spawnX,
spawnY,
spawnZ,
targetX,
targetY,
targetZ,
false);
ParticleHandler.spawnCustomParticle(passiveParticle, 35);
}
} else if (rand.nextInt(Math.max(1, 10 - particleRate)) == 0) {
spawnX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
spawnY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
spawnZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(
worldObj,
spawnX,
spawnY,
spawnZ,
targetX,
targetY,
targetZ,
false);
ParticleHandler.spawnCustomParticle(passiveParticle, 35);
}
}
} else {
targetX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
targetY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
targetZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
spawnX = xCoord + 0.5;
spawnY = cYCoord + 0.5;
spawnZ = zCoord + 0.5;
if (rand.nextFloat() < 0.05F) {
Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(
worldObj,
spawnX,
spawnY,
spawnZ,
targetX,
targetY,
targetZ,
true);
ParticleHandler.spawnCustomParticle(passiveParticle, 35);
}
if (particleRate > 0) {
if (particleRate > 10) {
for (int i = 0; i <= particleRate / 10; i++) {
targetX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
targetY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
targetZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(
worldObj,
spawnX,
spawnY,
spawnZ,
targetX,
targetY,
targetZ,
false);
ParticleHandler.spawnCustomParticle(passiveParticle, 35);
}
} else if (rand.nextInt(Math.max(1, 10 - particleRate)) == 0) {
targetX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
targetY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
targetZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
Particles.EnergyTransferParticle passiveParticle = new Particles.EnergyTransferParticle(
worldObj,
spawnX,
spawnY,
spawnZ,
targetX,
targetY,
targetZ,
false);
double sourceX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
double sourceY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
double sourceZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
double targetX = xCoord + 0.5;
double targetY = cYCoord + 0.5;
double targetZ = zCoord + 0.5;
if (rand.nextFloat() < 0.05F) {
EnergyTransferParticle passiveParticle = isReceivingEnergy
? new EnergyTransferParticle(worldObj, targetX, targetY, targetZ, sourceX, sourceY, sourceZ, true)
: new EnergyTransferParticle(worldObj, sourceX, sourceY, sourceZ, targetX, targetY, targetZ, true);
ParticleHandler.spawnCustomParticle(passiveParticle, 35);
}
if (particleRate > 0) {
if (particleRate > 10 || rand.nextInt(Math.max(1, 10 - particleRate)) == 0) {
int iterations = particleRate > 10 ? particleRate / 10 : 1;
for (int i = 0; i <= iterations; i++) {
sourceX = x + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
sourceY = y + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
sourceZ = z + 0.5 - disMod + (rand.nextFloat() * (disMod * 2));
EnergyTransferParticle passiveParticle = isReceivingEnergy
? new EnergyTransferParticle(
worldObj,
targetX,
targetY,
targetZ,
sourceX,
sourceY,
sourceZ,
false)
: new EnergyTransferParticle(
worldObj,
sourceX,
sourceY,
sourceZ,
targetX,
targetY,
targetZ,
false);
ParticleHandler.spawnCustomParticle(passiveParticle, 35);
}
}
@@ -295,8 +201,9 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
}
private boolean isValidStructure() {
return (isGlass(xCoord, yCoord + 1, zCoord) || isGlass(xCoord, yCoord - 1, zCoord))
&& (!isGlass(xCoord, yCoord + 1, zCoord) || !isGlass(xCoord, yCoord - 1, zCoord));
boolean hasGlassAbove = isGlass(xCoord, yCoord + 1, zCoord);
boolean hasGlassBelow = isGlass(xCoord, yCoord - 1, zCoord);
return hasGlassAbove != hasGlassBelow;
}
private boolean isGlass(int x, int y, int z) {
@@ -307,15 +214,15 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
active = compound.getBoolean("Active");
reciveEnergy = compound.getBoolean("Input");
isReceivingEnergy = compound.getBoolean("Input");
int i = compound.getInteger("Cores");
List<TileLocation> list = new ArrayList<TileLocation>();
List<TileLocation> list = new ArrayList<>();
for (int j = 0; j < i; j++) {
TileLocation l = new TileLocation();
l.readFromNBT(compound, "Core" + j);
list.add(l);
}
coreLocatios = list;
coreLocations = list;
selectedCore = compound.getInteger("SelectedCore");
particleRate = compound.getByte("ParticleRate");
}
@@ -325,11 +232,11 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
super.writeToNBT(compound);
compound.setBoolean("Active", active);
compound.setBoolean("Input", reciveEnergy);
int i = coreLocatios.size();
compound.setBoolean("Input", isReceivingEnergy);
int i = coreLocations.size();
compound.setInteger("Cores", i);
for (int j = 0; j < i; j++) {
coreLocatios.get(j).writeToNBT(compound, "Core" + j);
coreLocations.get(j).writeToNBT(compound, "Core" + j);
}
compound.setInteger("SelectedCore", selectedCore);
compound.setByte("ParticleRate", particleRate);
@@ -356,18 +263,16 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
if (getMaster() == null) return 0;
int received = reciveEnergy ? getMaster().receiveEnergy(maxReceive, simulate) : 0;
if (!simulate && received > 0)
particleRate = (byte) Math.min(20, received < 500 && received > 0 ? 1 : received / 500);
int received = isReceivingEnergy ? getMaster().receiveEnergy(maxReceive, simulate) : 0;
if (!simulate && received > 0) particleRate = (byte) Math.min(20, received < 500 ? 1 : received / 500);
return received;
}
@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
if (getMaster() == null || !getMaster().isOnline()) return 0;
int extracted = reciveEnergy ? 0 : getMaster().extractEnergy(maxExtract, simulate);
if (!simulate && extracted > 0)
particleRate = (byte) Math.min(20, extracted < 500 && extracted > 0 ? 1 : extracted / 500);
int extracted = isReceivingEnergy ? 0 : getMaster().extractEnergy(maxExtract, simulate);
if (!simulate && extracted > 0) particleRate = (byte) Math.min(20, extracted < 500 ? 1 : extracted / 500);
return extracted;
}
@@ -394,10 +299,10 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
0,
active,
new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 256));
if (lastTickReciveEnergy != reciveEnergy) lastTickReciveEnergy = (Boolean) sendObjectToClient(
if (isReceivedEnergyLastTick != isReceivingEnergy) isReceivedEnergyLastTick = (Boolean) sendObjectToClient(
References.BOOLEAN_ID,
1,
reciveEnergy,
isReceivingEnergy,
new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 256));
if (lastTickParticleRate != particleRate)
lastTickParticleRate = (Byte) sendObjectToClient(References.BYTE_ID, 2, particleRate);
@@ -407,15 +312,9 @@ public class TileEnergyPylon extends TileObjectSync implements IEnergyHandler, I
@Override
public void receiveObjectFromServer(int index, Object object) {
switch (index) {
case 0:
active = (Boolean) object;
break;
case 1:
reciveEnergy = (Boolean) object;
break;
case 2:
particleRate = (Byte) object;
break;
case 0 -> active = (Boolean) object;
case 1 -> isReceivingEnergy = (Boolean) object;
case 2 -> particleRate = (Byte) object;
}
}
@@ -6,8 +6,8 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import com.brandon3055.draconicevolution.common.blocks.multiblock.InvisibleMultiblock;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation;
import com.brandon3055.draconicevolution.common.handler.BalanceConfigHandler;
import com.brandon3055.draconicevolution.common.utills.LogHelper;
/**
@@ -23,46 +23,24 @@ public class TileInvisibleMultiblock extends TileEntity {
}
public boolean isMasterOnline() {
TileEnergyStorageCore tile = (worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord())
!= null
&& worldObj.getTileEntity(
master.getXCoord(),
master.getYCoord(),
master.getZCoord()) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) worldObj
.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord())
: null;
if (tile == null) {
return false;
}
return tile.online;
TileEntity tile = master.getTileEntity(worldObj);
return tile instanceof TileEnergyStorageCore core && core.isOnline();
}
public TileEnergyStorageCore getMaster() {
if (master == null) return null;
TileEnergyStorageCore tile = (worldObj.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord())
!= null
&& worldObj.getTileEntity(
master.getXCoord(),
master.getYCoord(),
master.getZCoord()) instanceof TileEnergyStorageCore)
? (TileEnergyStorageCore) worldObj
.getTileEntity(master.getXCoord(), master.getYCoord(), master.getZCoord())
: null;
return tile;
TileEntity tile = master.getTileEntity(worldObj);
return tile instanceof TileEnergyStorageCore core ? core : null;
}
@Override
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
// if (master != null)
master.writeToNBT(compound, "Key");
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
// if (master != null)
master.readFromNBT(compound, "Key");
}
@@ -79,32 +57,14 @@ public class TileInvisibleMultiblock extends TileEntity {
}
public void isStructureStillValid() {
if (getMaster() == null) {
TileEnergyStorageCore core = getMaster();
if (core == null) {
LogHelper.error("{Tile} Master = null reverting!");
revert();
InvisibleMultiblock.revertStructure(worldObj, xCoord, yCoord, zCoord);
return;
}
if (!getMaster().isOnline()) revert();
}
private void revert() {
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (meta == 0) {
worldObj.setBlock(
xCoord,
yCoord,
zCoord,
BalanceConfigHandler.energyStorageStructureOuterBlock,
BalanceConfigHandler.energyStorageStructureOuterBlockMetadata,
3);
} else if (meta == 1) {
worldObj.setBlock(
xCoord,
yCoord,
zCoord,
BalanceConfigHandler.energyStorageStructureBlock,
BalanceConfigHandler.energyStorageStructureBlockMetadata,
3);
if (!core.isOnline()) {
InvisibleMultiblock.revertStructure(worldObj, xCoord, yCoord, zCoord);
}
}
}
@@ -29,7 +29,9 @@ public class TilePortalBlock extends TileEntity {
@Override
@SideOnly(Side.CLIENT)
public void updateEntity() {
if (!worldObj.isRemote) return;
if (!worldObj.isRemote) {
return;
}
double distanceMod = Utills.getDistanceAtoB(
xCoord + 0.5,
yCoord + 0.5,
@@ -38,92 +40,76 @@ public class TilePortalBlock extends TileEntity {
RenderManager.renderPosY,
RenderManager.renderPosZ);
if (worldObj.rand.nextInt(Math.max((int) (distanceMod * (distanceMod / 5D)), 1)) == 0) {
if (blockMetadata == -1) blockMetadata = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
getBlockMetadata();
double rD1 = worldObj.rand.nextDouble();
double rD2 = worldObj.rand.nextDouble();
double rO1 = -0.1 + worldObj.rand.nextDouble() * 0.2;
double rO2 = -0.1 + worldObj.rand.nextDouble() * 0.2;
double offset1 = worldObj.rand.nextDouble();
double offset2 = worldObj.rand.nextDouble();
double smallOffset1 = -0.1 + worldObj.rand.nextDouble() * 0.2;
double smallOffset2 = -0.1 + worldObj.rand.nextDouble() * 0.2;
if (blockMetadata == 1 && RenderManager.renderPosZ < zCoord + 0.5) DraconicEvolution.proxy.spawnParticle(
new Particles.PortalParticle(
worldObj,
xCoord + rD1,
yCoord + rD2,
zCoord,
xCoord + rD1 + rO1,
yCoord + rD2 + rO2,
zCoord + 0.75),
double sourceX = xCoord;
double sourceY = yCoord;
double sourceZ = zCoord;
double targetX = xCoord;
double targetY = yCoord;
double targetZ = zCoord;
switch (blockMetadata) {
case 1 -> {
sourceX += offset1;
sourceY += offset2;
targetX += offset1 + smallOffset1;
targetY += offset2 + smallOffset2;
if (RenderManager.renderPosZ < zCoord + 0.5) {
targetZ += 0.75;
} else {
sourceZ += 1;
targetZ += 0.25;
}
}
case 2 -> {
sourceY += offset1;
sourceZ += offset2;
targetY += offset1 + smallOffset1;
targetZ += offset2 + smallOffset2;
if (RenderManager.renderPosX < xCoord + 0.5) {
targetX += 0.75;
} else {
sourceX += 1;
targetX += 0.25;
}
}
case 3 -> {
sourceX += offset1;
sourceZ += offset2;
targetX += offset1 + smallOffset1;
targetZ += offset2 + smallOffset2;
if (RenderManager.renderPosY < yCoord + 0.5) {
targetY += 0.75;
} else {
sourceY += 1;
targetY += 0.25;
}
}
}
DraconicEvolution.proxy.spawnParticle(
new Particles.PortalParticle(worldObj, sourceX, sourceY, sourceZ, targetX, targetY, targetZ),
256);
else if (blockMetadata == 1 && RenderManager.renderPosZ > zCoord + 0.5)
DraconicEvolution.proxy.spawnParticle(
new Particles.PortalParticle(
worldObj,
xCoord + rD1,
yCoord + rD2,
zCoord + 1,
xCoord + rD1 + rO1,
yCoord + rD2 + rO2,
zCoord + 0.25),
256);
else if (blockMetadata == 2 && RenderManager.renderPosX < xCoord + 0.5)
DraconicEvolution.proxy.spawnParticle(
new Particles.PortalParticle(
worldObj,
xCoord,
yCoord + rD1,
zCoord + rD2,
xCoord + 0.75,
yCoord + rD1 + rO1,
zCoord + rD2 + rO2),
256);
else if (blockMetadata == 2 && RenderManager.renderPosX > xCoord + 0.5)
DraconicEvolution.proxy.spawnParticle(
new Particles.PortalParticle(
worldObj,
xCoord + 1,
yCoord + rD1,
zCoord + rD2,
xCoord + 0.25,
yCoord + rD1 + rO1,
zCoord + rD2 + rO2),
256);
else if (blockMetadata == 3 && RenderManager.renderPosY > yCoord + 0.5)
DraconicEvolution.proxy.spawnParticle(
new Particles.PortalParticle(
worldObj,
xCoord + rD1,
yCoord + 1,
zCoord + rD2,
xCoord + rD1 + rO1,
yCoord + 0.25,
zCoord + rD2 + rO2),
256);
else if (blockMetadata == 3 && RenderManager.renderPosY < yCoord + 0.5)
DraconicEvolution.proxy.spawnParticle(
new Particles.PortalParticle(
worldObj,
xCoord + rD1,
yCoord,
zCoord + rD2,
xCoord + rD1 + rO1,
yCoord + 0.75,
zCoord + rD2 + rO2),
256);
}
}
public TileDislocatorReceptacle getMaster() {
return worldObj.getTileEntity(masterX, masterY, masterZ) instanceof TileDislocatorReceptacle
? (TileDislocatorReceptacle) worldObj.getTileEntity(masterX, masterY, masterZ)
: null;
TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ);
return tile instanceof TileDislocatorReceptacle receptacle ? receptacle : null;
}
public boolean isPortalStillValid() {
TileDislocatorReceptacle master = getMaster();
if (master == null || !master.isActive) return false;
master.validateActivePortal();
return master.isActive;
TileDislocatorReceptacle receptacle = getMaster();
if (receptacle == null || !receptacle.isActive) {
return false;
}
receptacle.validateActivePortal();
return receptacle.isActive;
}
@Override
@@ -1,7 +1,5 @@
package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor;
import java.util.Random;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
@@ -14,20 +12,19 @@ import com.brandon3055.brandonscore.common.utills.Utills;
*/
public class ReactorExplosion implements IProcess {
public static DamageSource fusionExplosion = new DamageSource("damage.de.fusionExplode").setExplosion()
public static final DamageSource FUSION_EXPLOSION = new DamageSource("damage.de.fusionExplode").setExplosion()
.setDamageBypassesArmor().setDamageIsAbsolute().setDamageAllowedInCreativeMode();
private World worldObj;
private int xCoord;
private int yCoord;
private int zCoord;
private float power;
private Random random = new Random();
private final World world;
private final int xCoord;
private final int yCoord;
private final int zCoord;
private final float power;
private boolean isDead;
private double expansion = 0;
public ReactorExplosion(World world, int x, int y, int z, float power) {
this.worldObj = world;
this.world = world;
this.xCoord = x;
this.yCoord = y;
this.zCoord = z;
@@ -38,17 +35,14 @@ public class ReactorExplosion implements IProcess {
@Override
public void updateProcess() {
int OD = (int) expansion;
int ID = OD - 1;
int size = (int) expansion;
for (int x = xCoord - size; x < xCoord + size; x++) {
for (int z = zCoord - size; z < zCoord + size; z++) {
double dist = Utills.getDistanceAtoB(x, z, xCoord, zCoord);
if (dist < OD && dist >= ID) {
double distance = Utills.getDistanceAtoB(x, z, xCoord, zCoord);
if (distance < expansion && distance >= size - 1) {
float tracePower = power - (float) (expansion / 10D);
tracePower *= 1F + ((random.nextFloat() - 0.5F) * 0.2);
ProcessHandler.addProcess(new ReactorExplosionTrace(worldObj, x, yCoord, z, tracePower, random));
tracePower *= 1F + (world.rand.nextFloat() - 0.5F) * 0.2;
ProcessHandler.addProcess(new ReactorExplosionTrace(world, x, yCoord, z, tracePower));
}
}
}
@@ -57,8 +51,6 @@ public class ReactorExplosion implements IProcess {
expansion += 1;
}
private boolean isDead = false;
@Override
public boolean isDead() {
return isDead;
@@ -1,7 +1,6 @@
package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
@@ -17,20 +16,19 @@ import com.brandon3055.brandonscore.common.handlers.IProcess;
*/
public class ReactorExplosionTrace implements IProcess {
private World worldObj;
private int xCoord;
private int yCoord;
private int zCoord;
private float power;
private Random random;
private final World world;
private final int xCoord;
private final int yCoord;
private final int zCoord;
private final float power;
private boolean isDead = false;
public ReactorExplosionTrace(World world, int x, int y, int z, float power, Random random) {
this.worldObj = world;
public ReactorExplosionTrace(World world, int x, int y, int z, float power) {
this.world = world;
this.xCoord = x;
this.yCoord = y;
this.zCoord = z;
this.power = power;
this.random = random;
}
@Override
@@ -39,52 +37,54 @@ public class ReactorExplosionTrace implements IProcess {
float energy = power * 10;
for (int y = yCoord; y > 0 && energy > 0; y--) {
Block block = worldObj.getBlock(xCoord, y, zCoord);
Block block = world.getBlock(xCoord, y, zCoord);
List<Entity> entities = worldObj.getEntitiesWithinAABB(
List<Entity> entities = world.getEntitiesWithinAABB(
Entity.class,
AxisAlignedBB.getBoundingBox(xCoord, y, zCoord, xCoord + 1, y + 1, zCoord + 1));
for (Entity entity : entities) entity.attackEntityFrom(ReactorExplosion.fusionExplosion, power * 100);
for (Entity entity : entities) {
entity.attackEntityFrom(ReactorExplosion.FUSION_EXPLOSION, power * 100);
}
energy -= block instanceof BlockLiquid ? 10 : block.getExplosionResistance(null);
boolean blockRemoved = false;
if (energy >= 0 && block != Blocks.air) {
worldObj.setBlockToAir(xCoord, y, zCoord);
world.setBlockToAir(xCoord, y, zCoord);
blockRemoved = true;
}
energy -= 0.5F + (0.1F * (yCoord - y));
energy -= 0.5F + 0.1F * (yCoord - y);
if (energy <= 0 && random.nextInt(20) == 0 && blockRemoved) {
if (random.nextInt(3) > 0) worldObj.setBlock(xCoord, y, zCoord, Blocks.fire);
else {
worldObj.setBlock(xCoord, y, zCoord, Blocks.flowing_lava);
// worldObj.scheduleBlockUpdate(xCoord, y, zCoord, Blocks.flowing_lava, 100);
if (energy <= 0 && world.rand.nextInt(20) == 0 && blockRemoved) {
if (world.rand.nextInt(3) > 0) {
world.setBlock(xCoord, y, zCoord, Blocks.fire);
} else {
world.setBlock(xCoord, y, zCoord, Blocks.flowing_lava);
}
}
}
energy = power * 20;
yCoord++;
for (int y = yCoord; y < 255 && energy > 0; y++) {
Block block = worldObj.getBlock(xCoord, y, zCoord);
for (int y = yCoord + 1; y < 255 && energy > 0; y++) {
Block block = world.getBlock(xCoord, y, zCoord);
List<Entity> entities = worldObj.getEntitiesWithinAABB(
List<Entity> entities = world.getEntitiesWithinAABB(
Entity.class,
AxisAlignedBB.getBoundingBox(xCoord, y, zCoord, xCoord + 1, y + 1, zCoord + 1));
for (Entity entity : entities) entity.attackEntityFrom(ReactorExplosion.fusionExplosion, power * 100);
for (Entity entity : entities) {
entity.attackEntityFrom(ReactorExplosion.FUSION_EXPLOSION, power * 100);
}
energy -= block instanceof BlockLiquid ? 10 : block.getExplosionResistance(null);
if (energy >= 0) worldObj.setBlockToAir(xCoord, y, zCoord);
if (energy >= 0) {
world.setBlockToAir(xCoord, y, zCoord);
}
energy -= 0.5F + (0.1F * (y - yCoord));
}
isDead = true;
}
private boolean isDead = false;
@Override
public boolean isDead() {
return isDead;
@@ -1,8 +1,10 @@
package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
@@ -10,7 +12,9 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.brandonscore.BrandonsCore;
@@ -21,6 +25,7 @@ import com.brandon3055.draconicevolution.client.ReactorSound;
import com.brandon3055.draconicevolution.client.gui.GuiHandler;
import com.brandon3055.draconicevolution.client.render.particle.Particles;
import com.brandon3055.draconicevolution.common.blocks.multiblock.IReactorPart;
import com.brandon3055.draconicevolution.common.blocks.multiblock.IReactorPart.ComparatorMode;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation;
import com.brandon3055.draconicevolution.common.handler.ConfigHandler;
import com.brandon3055.draconicevolution.common.lib.References;
@@ -36,14 +41,29 @@ import cpw.mods.fml.relauncher.SideOnly;
*/
public class TileReactorCore extends TileObjectSync {
public static final int MAX_SLAVE_RANGE = 10;
public static final int STATE_OFFLINE = 0;
public static final int STATE_START = 1;
public static final int STATE_ONLINE = 2;
public static final int STATE_STOP = 3;
public static final int STATE_INVALID = 4;
public static final int MAXIMUM_PART_DISTANCE = 10;
public int reactorState = 0;
public enum ReactorState {
OFFLINE,
STARTING,
ONLINE,
STOPPING,
INVALID;
private static final ReactorState[] values = values();
public static ReactorState getState(int ordinal) {
return ordinal >= 0 && ordinal < values.length ? values[ordinal] : INVALID;
}
public String toLocalizedString(boolean canStart) {
return StatCollector.translateToLocal(
this == STARTING && canStart ? "gui.de.status1_5.txt" : "gui.de.status" + ordinal() + ".txt");
}
}
public ReactorState reactorState = ReactorState.OFFLINE;
public float renderRotation = 0;
public float renderSpeed = 0;
public boolean isStructureValid = false;
@@ -55,8 +75,7 @@ public class TileReactorCore extends TileObjectSync {
public int reactorFuel = 0;
public int convertedFuel = 0; // The amount of fuel that has converted
public double conversionUnit = 0; // used to smooth out the conversion between int and floating point. When >= 1
// minus one and convert one
// int worth of fuel
// minus one and convert one int worth of fuel
public double reactionTemperature = 20;
public double maxReactTemperature = 10000;
@@ -70,24 +89,7 @@ public class TileReactorCore extends TileObjectSync {
@SideOnly(Side.CLIENT)
private ReactorSound reactorSound;
// #######################
// TODO DONT FORGET TO ACTUALLY FINISH ALL THESE THINGS!!!!
// Check //-Bounding box
// Check //-Custom player collision
// Check //-Finish stabilizer place and break mechanics
// Check //-Have the GUI tell you if the structure is invalid
// Check //-Config
// TODO things for later
// -GUI info (maby speed up gui sync via the container)
// -GUI warning red bars
// -Maby get around to setting the angle of the stabiliser elements
// Check //-SOUND!!!!!
// Check //-CC Integration
// Check //-Redstone
// -Add reactor and gates to tablet
public List<TileLocation> stabilizerLocations = new ArrayList<TileLocation>();
public List<TileLocation> stabilizerLocations = new ArrayList<>();
@Override
public void updateEntity() {
@@ -98,25 +100,14 @@ public class TileReactorCore extends TileObjectSync {
renderSpeed = (float) Math.min((reactionTemperature - 20) / 2000D, 1D);
stabilizerRender = (float) Math.min(fieldCharge / (maxFieldCharge * 0.1D), 1D);
renderRotation += renderSpeed;
// LogHelper.info(renderSpeed +" "+(reactionTemperature));
checkPlayerCollision();
return;
}
// else injectEnergy(10000000);
switch (reactorState) {
case STATE_OFFLINE:
offlineTick();
break;
case STATE_START:
startingTick();
break;
case STATE_ONLINE:
runTick();
break;
case STATE_STOP:
runTick();
break;
case OFFLINE -> offlineTick();
case STARTING -> startingTick();
case ONLINE, STOPPING -> runTick();
}
detectAndSendChanges();
@@ -124,30 +115,31 @@ public class TileReactorCore extends TileObjectSync {
@SideOnly(Side.CLIENT)
private void updateSound() {
if (reactorSound == null)
if (reactorSound == null) {
reactorSound = (ReactorSound) DraconicEvolution.proxy.playISound(new ReactorSound(this));
}
}
private void checkPlayerCollision() {
EntityPlayer player = BrandonsCore.proxy.getClientPlayer();
double distance = Utills
.getDistanceAtoB(player.posX, player.posY, player.posZ, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
if (distance < (getCoreDiameter() / 2) + 0.5) {
double dMod = 1D - (distance / Math.max(0.1, (getCoreDiameter() / 2) + 0.5));
double coreRadiusWithMargin = getCoreRadius() + 0.5;
if (distance < coreRadiusWithMargin) {
double distanceMod = 1D - (distance / Math.max(0.1, coreRadiusWithMargin));
double offsetX = player.posX - xCoord + 0.5;
double offsetY = player.posY - yCoord + 0.5;
double offsetZ = player.posZ - zCoord + 0.5;
double m = 1D * dMod;
player.addVelocity(offsetX * m, offsetY * m, offsetZ * m);
player.addVelocity(offsetX * distanceMod, offsetY * distanceMod, offsetZ * distanceMod);
}
}
private void offlineTick() {
if (reactionTemperature > 20) reactionTemperature -= 0.5;
if (fieldCharge > 0) fieldCharge -= maxFieldCharge * 0.0005;
else if (fieldCharge < 0) fieldCharge = 0;
if (energySaturation > 0) energySaturation -= maxEnergySaturation * 0.000001;
else if (energySaturation < 0) energySaturation = 0;
if (reactionTemperature > 20) {
reactionTemperature -= 0.5;
}
fieldCharge = Math.max(0, fieldCharge - maxFieldCharge * 0.0005);
energySaturation = (int) Math.max(0, energySaturation - maxEnergySaturation * 0.000001);
}
private void startingTick() {
@@ -155,8 +147,8 @@ public class TileReactorCore extends TileObjectSync {
int totalFuel = reactorFuel + convertedFuel;
maxFieldCharge = totalFuel * 96.45061728395062 * 100;
maxEnergySaturation = (int) (totalFuel * 96.45061728395062 * 1000);
if (energySaturation > maxEnergySaturation) energySaturation = maxEnergySaturation;
if (fieldCharge > maxFieldCharge) fieldCharge = maxFieldCharge;
energySaturation = Math.min(energySaturation, maxEnergySaturation);
fieldCharge = Math.min(fieldCharge, maxFieldCharge);
startupInitialized = true;
}
}
@@ -171,83 +163,59 @@ public class TileReactorCore extends TileObjectSync {
private void runTick() {
// Inverted core saturation (if multiplied by 100 this creates infinite numbers which breaks the code)
double saturation = ((double) energySaturation / (double) maxEnergySaturation);
double saturationI = (1D - ((double) energySaturation / (double) maxEnergySaturation)) * 99D;
double temp = ((reactionTemperature) / maxReactTemperature) * 50D;
double saturation = (double) energySaturation / (double) maxEnergySaturation;
double saturationI = (1D - saturation) * 99D;
double temp = (reactionTemperature / maxReactTemperature) * 50D;
// The conversion level. Ranges from -0.3 to 1.0
double conversion = (((double) convertedFuel + conversionUnit)
/ ((double) (convertedFuel + reactorFuel) - conversionUnit)
* 1.3) - 0.3D;
double conversion = (convertedFuel + conversionUnit) / (convertedFuel + reactorFuel - conversionUnit) * 1.3
- 0.3D;
// Temperature Calculation
double tempOffset = 444.7; // Adjusts where the temp falls to at 100% saturation
final double tempOffset = 444.7; // Adjusts where the temp falls to at 100% saturation
// The exponential temperature rise which increases as the core saturation goes down
double tempRiseExpo = (saturationI * saturationI * saturationI) / (100 - saturationI) + tempOffset;
double tempRiseExpo = Math.pow(saturationI, 3) / (100 - saturationI) + tempOffset;
// This is used to add resistance as the temp rises because the hotter something gets the more energy it takes
// to get it hotter
double tempRiseResist = (temp * temp * temp * temp) / (100 - temp);
double tempRiseResist = Math.pow(temp, 4) / (100 - temp);
// This puts all the numbers together and gets the value to raise or lower the temp by this tick. This is
// dealing with very big numbers so the result is divided by 10000
double riseAmount = (tempRiseExpo - (tempRiseResist * (1D - conversion)) + conversion * 1000) / 10000;
if (reactorState == STATE_STOP) {
double riseAmount = (tempRiseExpo - tempRiseResist * (1D - conversion) + conversion * 1000) / 10000;
if (reactorState == ReactorState.STOPPING) {
if (reactionTemperature <= 2001) {
reactorState = STATE_OFFLINE;
reactorState = ReactorState.OFFLINE;
startupInitialized = false;
return;
}
if (energySaturation >= maxEnergySaturation * 0.99 && reactorFuel > 0)
if (energySaturation >= maxEnergySaturation * 0.99 && reactorFuel > 0) {
reactionTemperature -= 1D - conversion;
else reactionTemperature += riseAmount * 10;
} else reactionTemperature += riseAmount * 10;
// ======================
} else {
reactionTemperature += riseAmount * 10;
}
} else {
reactionTemperature += riseAmount * 10;
}
// Energy Calculation
int baseMaxRFt = (int) ((maxEnergySaturation / 1000D) * ConfigHandler.reactorOutputMultiplier * 1.5D);
int maxRFt = (int) (baseMaxRFt * (1D + (conversion * 2)));
int maxRFt = (int) (baseMaxRFt * (1D + conversion * 2));
generationRate = (1D - saturation) * maxRFt;
energySaturation += generationRate;
// LogHelper.info((1D - saturation) * maxRFt);
// ======================
// When temp < 1000 power drain is 0, when temp > 2000 power drain is 1, when temp > 8000 power drain increases
// exponentially
tempDrainFactor = reactionTemperature > 8000
? 1 + ((reactionTemperature - 8000) * (reactionTemperature - 8000) * 0.0000025)
tempDrainFactor = reactionTemperature > 8000 ? 1 + (Math.pow(reactionTemperature - 8000, 2) * 0.0000025)
: reactionTemperature > 2000 ? 1 : reactionTemperature > 1000 ? (reactionTemperature - 1000) / 1000 : 0;
// todo add to guiInfo
// -temp drain factor
// -mass
// -generation
// -field drain
// Field Drain Calculation
fieldDrain = (int) Math
.min(tempDrainFactor * (1D - saturation) * (baseMaxRFt / 10.923556), (double) Integer.MAX_VALUE); // <(baseMaxRFt/make
// smaller
// to
// increase
// field
// power
// drain)
// (baseMaxRFt/make smaller to increase field power drain)
fieldDrain = (int) Math.min(tempDrainFactor * (1D - saturation) * (baseMaxRFt / 10.923556), Integer.MAX_VALUE);
double fieldNegPercent = 1D - (fieldCharge / maxFieldCharge);
double fieldNegPercent = 1D - fieldCharge / maxFieldCharge;
fieldInputRate = fieldDrain / fieldNegPercent;
// LogHelper.info(fieldDrain+" "+tempDrainFactor+" "+(1D-saturation)+" "+tempDrainFactor * (1D-saturation) *
// (baseMaxRFt/10.923556));
fieldCharge -= fieldDrain;
// ======================
// Calculate Fuel Usage
fuelUseRate = tempDrainFactor * (1D - saturation) * (0.001 * ConfigHandler.reactorFuelUsageMultiplier); // <Last
// number
// is
// base
// fuel
// usage
// rate
fuelUseRate = tempDrainFactor * (1D - saturation) * (0.001 * ConfigHandler.reactorFuelUsageMultiplier);
conversionUnit += fuelUseRate;
if (conversionUnit >= 1 && reactorFuel > 0) {
conversionUnit--;
@@ -255,326 +223,329 @@ public class TileReactorCore extends TileObjectSync {
convertedFuel++;
}
// ====================
// Make BOOM!!!
if ((fieldCharge <= 0) && !hasExploded) {
if (fieldCharge <= 0 && !hasExploded) {
hasExploded = true;
goBoom();
}
// ===========
}
private void goBoom() {
if (!ConfigHandler.enableReactorBigBoom) {
worldObj.createExplosion(null, xCoord, yCoord, zCoord, 5, true);
} else {
// float power = 10F + Math.min(10F, ((float) (convertedFuel + reactorFuel) / 10369F) * 10F);
float power = 2F + (((float) (convertedFuel + reactorFuel) / 10369F) * 18F);
if (ConfigHandler.enableReactorBigBoom) {
float power = 2F + ((float) (convertedFuel + reactorFuel) / 10369F * 18F);
ProcessHandler.addProcess(new ReactorExplosion(worldObj, xCoord, yCoord, zCoord, power));
sendObjectToClient(
References.INT_ID,
100,
(int) (power * 10F),
new NetworkRegistry.TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 512));
} else {
worldObj.createExplosion(null, xCoord, yCoord, zCoord, 5, true);
}
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
public void validateStructure() {
boolean updateRequired = false;
// Check that all of the stabilizers are still valid
Iterator<TileLocation> i = stabilizerLocations.iterator();
List<TileReactorStabilizer> stabilizers = new ArrayList<TileReactorStabilizer>();
while (i.hasNext()) {
TileLocation location = i.next();
if (!(location.getTileEntity(worldObj) instanceof TileReactorStabilizer)
|| !((TileReactorStabilizer) location.getTileEntity(worldObj)).masterLocation
.isThisLocation(xCoord, yCoord, zCoord)) {
i.remove();
updateRequired = true;
} else stabilizers.add((TileReactorStabilizer) location.getTileEntity(worldObj));
}
private boolean isFacingToCore(int x, int y, int z, IReactorPart part) {
ForgeDirection facing = part.getFacing();
int offsetX = Integer.signum(xCoord - x);
int offsetY = Integer.signum(yCoord - y);
int offsetZ = Integer.signum(zCoord - z);
return offsetX == facing.offsetX && offsetY == facing.offsetY && offsetZ == facing.offsetZ;
}
// Check that there are 4 stabilizers in the correct configuration
isStructureValid = false;
List<TileReactorStabilizer> checkList = new ArrayList<TileReactorStabilizer>();
for (TileReactorStabilizer stabilizer : stabilizers) {
if (checkList.contains(stabilizer)) continue;
for (TileReactorStabilizer comp : stabilizers) {
if (!(comp == stabilizer || checkList.contains(comp))
&& ForgeDirection.getOrientation(comp.facingDirection)
== ForgeDirection.getOrientation(stabilizer.facingDirection).getOpposite()) {
checkList.add(comp);
checkList.add(stabilizer);
if (checkList.size() == 4) {
isStructureValid = true;
if (reactorState == STATE_INVALID) reactorState = STATE_OFFLINE;
break;
public void updateReactorParts(boolean shouldSetUp) {
stabilizerLocations.clear();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
for (int distance = 1; distance <= MAXIMUM_PART_DISTANCE; distance++) {
int targetX = xCoord + direction.offsetX * distance;
int targetY = yCoord + direction.offsetY * distance;
int targetZ = zCoord + direction.offsetZ * distance;
TileEntity tile = worldObj.getTileEntity(targetX, targetY, targetZ);
if (tile instanceof IReactorPart part && isFacingToCore(targetX, targetY, targetZ, part)) {
if (shouldSetUp) {
part.setUp(new TileLocation(xCoord, yCoord, zCoord));
}
if (tile instanceof TileReactorStabilizer) {
stabilizerLocations.add(new TileLocation(targetX, targetY, targetZ));
}
break;
}
}
}
}
for (TileReactorStabilizer stabilizer : stabilizers) {
if (Utills.getDistanceAtoB(stabilizer.xCoord, stabilizer.yCoord, stabilizer.zCoord, xCoord, yCoord, zCoord)
< (getMaxCoreDiameter() / 2) + 1) {
isStructureValid = false;
break;
public void validateStructure() {
final double margin = 0.5D;
final double coreRadiusSquared = Math.pow(getCoreRadius() + margin, 2);
boolean updateRequired = false;
int stabilizersCount = 0;
Iterator<TileLocation> iterator = stabilizerLocations.iterator();
while (iterator.hasNext()) {
TileLocation location = iterator.next();
if (location.getDistanceSquared(xCoord, yCoord, zCoord) > coreRadiusSquared) {
TileEntity tile = location.getTileEntity(worldObj);
if (tile instanceof TileReactorStabilizer stabilizer) {
if (stabilizer.masterLocation.isThisLocation(xCoord, yCoord, zCoord)) {
stabilizersCount++;
continue;
}
}
}
iterator.remove();
updateRequired = true;
}
if (!isStructureValid) {
reactorState = STATE_INVALID;
isStructureValid = stabilizersCount == 4;
if (isStructureValid) {
if (reactorState == ReactorState.INVALID) {
reactorState = ReactorState.OFFLINE;
}
} else {
reactorState = ReactorState.INVALID;
if (reactionTemperature >= 2000) {
goBoom();
}
}
if (updateRequired) worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
if (updateRequired) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
public void onPlaced() {
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
boolean flag = false;
for (int i = 1; i < MAX_SLAVE_RANGE && !flag; i++) {
TileLocation location = new TileLocation(
xCoord + direction.offsetX * i,
yCoord + direction.offsetY * i,
zCoord + direction.offsetZ * i);
if (location.getTileEntity(worldObj) != null) {
if (location.getTileEntity(worldObj) instanceof IReactorPart
&& !((IReactorPart) location.getTileEntity(worldObj)).getMaster().initialized)
((IReactorPart) location.getTileEntity(worldObj)).checkForMaster();
flag = true;
}
}
}
updateReactorParts(true);
validateStructure();
}
public void onBroken() {
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
for (int i = 1; i < MAX_SLAVE_RANGE; i++) {
TileLocation location = new TileLocation(
xCoord + direction.offsetX * i,
yCoord + direction.offsetY * i,
zCoord + direction.offsetZ * i);
if (location.getTileEntity(worldObj) instanceof IReactorPart
&& ((IReactorPart) location.getTileEntity(worldObj)).getMaster()
.compareTo(new TileLocation(xCoord, yCoord, zCoord)) == 0)
((IReactorPart) location.getTileEntity(worldObj)).shutDown();
for (int distance = 1; distance <= MAXIMUM_PART_DISTANCE; distance++) {
TileEntity tile = worldObj.getTileEntity(
xCoord + direction.offsetX * distance,
yCoord + direction.offsetY * distance,
zCoord + direction.offsetZ * distance);
if (tile instanceof IReactorPart part) {
if (part.getMasterLocation().isThisLocation(xCoord, yCoord, zCoord)) {
part.shutDown();
}
break;
}
}
}
if (reactionTemperature >= 2000) {
goBoom();
}
}
public boolean onStructureRightClicked(EntityPlayer player) {
if (!worldObj.isRemote)
if (!worldObj.isRemote) {
player.openGui(DraconicEvolution.instance, GuiHandler.GUIID_REACTOR, worldObj, xCoord, yCoord, zCoord);
}
return true;
}
public int injectEnergy(int RF) {
int received = 0;
if (reactorState == STATE_START) {
if (!startupInitialized) return 0;
if (fieldCharge < (maxFieldCharge / 2)) {
received = Math.min(RF, (int) (maxFieldCharge / 2) - (int) fieldCharge + 1);
fieldCharge += received;
if (fieldCharge > (maxFieldCharge / 2)) fieldCharge = (maxFieldCharge / 2);
} else if (energySaturation < (maxEnergySaturation / 2)) {
received = Math.min(RF, (maxEnergySaturation / 2) - energySaturation);
energySaturation += received;
} else if (reactionTemperature < 2000) {
received = RF;
reactionTemperature += ((double) received / (1000D + (reactorFuel * 10)));
if (reactionTemperature > 2000) reactionTemperature = 2000;
public int injectEnergy(int energyToInject) {
int energyInjected = 0;
if (reactorState == ReactorState.STARTING) {
if (!startupInitialized) {
return 0;
}
} else if (reactorState == STATE_ONLINE || reactorState == STATE_STOP) {
fieldCharge += (RF * (1D - (fieldCharge / maxFieldCharge)));
if (fieldCharge > maxFieldCharge) fieldCharge = maxFieldCharge;
return RF;
if (fieldCharge < maxFieldCharge / 2) {
energyInjected = Math.min(energyToInject, (int) (maxFieldCharge / 2) - (int) fieldCharge + 1);
fieldCharge += energyInjected;
if (fieldCharge > maxFieldCharge / 2) {
fieldCharge = maxFieldCharge / 2;
}
} else if (energySaturation < maxEnergySaturation / 2) {
energyInjected = Math.min(energyToInject, maxEnergySaturation / 2 - energySaturation);
energySaturation += energyInjected;
} else if (reactionTemperature < 2000) {
energyInjected = energyToInject;
reactionTemperature += (double) energyInjected / (1000D + reactorFuel * 10);
if (reactionTemperature > 2000) {
reactionTemperature = 2000;
}
}
} else if (reactorState == ReactorState.ONLINE || reactorState == ReactorState.STOPPING) {
energyInjected = energyToInject;
fieldCharge += energyInjected * (1D - fieldCharge / maxFieldCharge);
fieldCharge = Math.min(fieldCharge, maxFieldCharge);
}
return received;
return energyInjected;
}
public boolean canStart() {
validateStructure();
return reactionTemperature >= 2000 && fieldCharge >= (maxFieldCharge / 2)
&& energySaturation >= (maxEnergySaturation / 2)
&& isStructureValid
return isStructureValid && reactionTemperature >= 2000
&& fieldCharge >= maxFieldCharge / 2
&& energySaturation >= maxEnergySaturation / 2
&& convertedFuel + reactorFuel + conversionUnit >= 144;
}
public boolean canCharge() {
validateStructure();
return reactorState != STATE_ONLINE && isStructureValid && convertedFuel + reactorFuel + conversionUnit >= 144;
return isStructureValid && reactorState != ReactorState.ONLINE
&& convertedFuel + reactorFuel + conversionUnit >= 144;
}
public boolean canStop() {
validateStructure();
return reactorState != STATE_OFFLINE && isStructureValid;
return isStructureValid && reactorState != ReactorState.OFFLINE;
}
public void processButtonPress(int button) {
if (button == 0 && canCharge()) reactorState = STATE_START;
else if (button == 1 && canStart()) reactorState = STATE_ONLINE;
else if (button == 2 && canStop()) reactorState = STATE_STOP;
if (button == 0 && canCharge()) {
reactorState = ReactorState.STARTING;
} else if (button == 1 && canStart()) {
reactorState = ReactorState.ONLINE;
} else if (button == 2 && canStop()) {
reactorState = ReactorState.STOPPING;
}
}
public double getCoreDiameter() { // todo adjust so the core dose not expand before 1000>2000c
// return (((1F + Math.sin((float)tick/50F)) / 2F) * 4) + 0.3;
public double getCoreRadius() {
double volume = (double) (reactorFuel + convertedFuel) / 1296D;
volume *= 1 + (reactionTemperature / maxReactTemperature) * 10D;
return Math.cbrt(volume / (4 / 3 * Math.PI)) * 2;
return Math.cbrt(volume / (4D / 3D * Math.PI));
}
public double getMaxCoreDiameter() {
// return (((1F + Math.sin((float)tick/50F)) / 2F) * 4) + 0.3;
double volume = (double) (reactorFuel + convertedFuel) / 1296D;
volume *= 1 + 1 * 10D;
return Math.cbrt(volume / (4 / 3 * Math.PI)) * 2;
public double getCoreDiameter() {
return getCoreRadius() * 2;
}
private boolean isStructureValidCach = false;
private boolean startupInitializedCach = false;
private int reactorStateCach = -1;
private int reactorFuelCach = -1;
private int convertedFuelCach = -1;
private int energySaturationCach = -1;
private int maxEnergySaturationCach = -1;
private double reactionTemperatureCach = -1;
private double maxReactTemperatureCach = -1;
private double fieldChargeCach = -1;
private double maxFieldChargeCach = -1;
private boolean isStructureValidCache = false;
private boolean startupInitializedCache = false;
private int reactorStateCache = -1;
private int reactorFuelCache = -1;
private int convertedFuelCache = -1;
private int energySaturationCache = -1;
private int maxEnergySaturationCache = -1;
private double reactionTemperatureCache = -1;
private double maxReactTemperatureCache = -1;
private double fieldChargeCache = -1;
private double maxFieldChargeCache = -1;
private void detectAndSendChanges() {
NetworkRegistry.TargetPoint tp = new NetworkRegistry.TargetPoint(
NetworkRegistry.TargetPoint targetPoint = new NetworkRegistry.TargetPoint(
worldObj.provider.dimensionId,
xCoord,
yCoord,
zCoord,
128);
if (reactionTemperatureCach != reactionTemperature)
reactionTemperatureCach = (Double) sendObjectToClient(References.DOUBLE_ID, 8, reactionTemperature, tp);
if (tick % 10 != 0) return;
if (isStructureValidCach != isStructureValid)
isStructureValidCach = (Boolean) sendObjectToClient(References.BOOLEAN_ID, 0, isStructureValid, tp);
// if (isActiveCach != isActive) isActiveCach = (Boolean) sendObjectToClient(References.BOOLEAN_ID,
// 1, isActive, tp);
if (startupInitializedCach != startupInitialized)
startupInitializedCach = (Boolean) sendObjectToClient(References.BOOLEAN_ID, 2, startupInitialized, tp);
if (reactorStateCach != reactorState)
reactorStateCach = (Integer) sendObjectToClient(References.INT_ID, 3, reactorState, tp);
if (reactorFuelCach != reactorFuel)
reactorFuelCach = (Integer) sendObjectToClient(References.INT_ID, 4, reactorFuel, tp);
if (convertedFuelCach != convertedFuel)
convertedFuelCach = (Integer) sendObjectToClient(References.INT_ID, 5, convertedFuel, tp);
if (energySaturationCach != energySaturation)
energySaturationCach = (Integer) sendObjectToClient(References.INT_ID, 6, energySaturation, tp);
if (maxEnergySaturationCach != maxEnergySaturation)
maxEnergySaturationCach = (Integer) sendObjectToClient(References.INT_ID, 7, maxEnergySaturation, tp);
if (maxReactTemperatureCach != maxReactTemperature)
maxReactTemperatureCach = (Double) sendObjectToClient(References.DOUBLE_ID, 9, maxReactTemperature, tp);
if (fieldChargeCach != fieldCharge)
fieldChargeCach = (Double) sendObjectToClient(References.DOUBLE_ID, 10, fieldCharge, tp);
if (maxFieldChargeCach != maxFieldCharge)
maxFieldChargeCach = (Double) sendObjectToClient(References.DOUBLE_ID, 11, maxFieldCharge, tp);
if (reactionTemperatureCache != reactionTemperature) {
reactionTemperatureCache = (double) sendObjectToClient(
References.DOUBLE_ID,
8,
reactionTemperature,
targetPoint);
}
if (tick % 10 != 0) {
return;
}
if (isStructureValidCache != isStructureValid) {
isStructureValidCache = (boolean) sendObjectToClient(
References.BOOLEAN_ID,
0,
isStructureValid,
targetPoint);
}
if (startupInitializedCache != startupInitialized) {
startupInitializedCache = (boolean) sendObjectToClient(
References.BOOLEAN_ID,
2,
startupInitialized,
targetPoint);
}
if (reactorStateCache != reactorState.ordinal()) {
reactorStateCache = (int) sendObjectToClient(References.INT_ID, 3, reactorState.ordinal(), targetPoint);
}
if (reactorFuelCache != reactorFuel) {
reactorFuelCache = (int) sendObjectToClient(References.INT_ID, 4, reactorFuel, targetPoint);
}
if (convertedFuelCache != convertedFuel) {
convertedFuelCache = (int) sendObjectToClient(References.INT_ID, 5, convertedFuel, targetPoint);
}
if (energySaturationCache != energySaturation) {
energySaturationCache = (int) sendObjectToClient(References.INT_ID, 6, energySaturation, targetPoint);
}
if (maxEnergySaturationCache != maxEnergySaturation) {
maxEnergySaturationCache = (int) sendObjectToClient(References.INT_ID, 7, maxEnergySaturation, targetPoint);
}
if (maxReactTemperatureCache != maxReactTemperature) {
maxReactTemperatureCache = (double) sendObjectToClient(
References.DOUBLE_ID,
9,
maxReactTemperature,
targetPoint);
}
if (fieldChargeCache != fieldCharge) {
fieldChargeCache = (double) sendObjectToClient(References.DOUBLE_ID, 10, fieldCharge, targetPoint);
}
if (maxFieldChargeCache != maxFieldCharge) {
maxFieldChargeCache = (double) sendObjectToClient(References.DOUBLE_ID, 11, maxFieldCharge, targetPoint);
}
}
public int getComparatorOutput(int rsMode) {
switch (rsMode) {
case IReactorPart.RMODE_TEMP:
return toRSStrength(reactionTemperature, maxReactTemperature, rsMode);
case IReactorPart.RMODE_TEMP_INV:
return 15 - toRSStrength(reactionTemperature, maxReactTemperature, rsMode);
case IReactorPart.RMODE_FIELD:
return toRSStrength(fieldCharge, maxFieldCharge, rsMode);
case IReactorPart.RMODE_FIELD_INV:
return 15 - toRSStrength(fieldCharge, maxFieldCharge, rsMode);
case IReactorPart.RMODE_SAT:
return toRSStrength(energySaturation, maxEnergySaturation, rsMode);
case IReactorPart.RMODE_SAT_INV:
return 15 - toRSStrength(energySaturation, maxEnergySaturation, rsMode);
case IReactorPart.RMODE_FUEL:
return toRSStrength(convertedFuel + conversionUnit, reactorFuel - conversionUnit, rsMode);
case IReactorPart.RMODE_FUEL_INV:
return 15 - toRSStrength(convertedFuel + conversionUnit, reactorFuel - conversionUnit, rsMode);
}
return 0;
public int getComparatorOutput(ComparatorMode comparatorMode) {
return switch (comparatorMode) {
case TEMPERATURE -> toRedstoneStrength(reactionTemperature, maxReactTemperature, comparatorMode);
case TEMPERATURE_INVERTED -> 15
- toRedstoneStrength(reactionTemperature, maxReactTemperature, comparatorMode);
case FIELD_CHARGE -> toRedstoneStrength(fieldCharge, maxFieldCharge, comparatorMode);
case FIELD_CHARGE_INVERTED -> 15 - toRedstoneStrength(fieldCharge, maxFieldCharge, comparatorMode);
case ENERGY_SATURATION -> toRedstoneStrength(energySaturation, maxEnergySaturation, comparatorMode);
case ENERGY_SATURATION_INVERTED -> 15
- toRedstoneStrength(energySaturation, maxEnergySaturation, comparatorMode);
case CONVERTED_FUEL -> toRedstoneStrength(
convertedFuel + conversionUnit,
reactorFuel - conversionUnit,
comparatorMode);
case CONVERTED_FUEL_INVERTED -> 15
- toRedstoneStrength(convertedFuel + conversionUnit, reactorFuel - conversionUnit, comparatorMode);
};
}
private int toRSStrength(double value, double maxValue, int mode) {
if (maxValue == 0) return 0;
double d = value / maxValue;
int rs = (int) (d * 15D);
switch (mode) {
case IReactorPart.RMODE_FIELD:
case IReactorPart.RMODE_FIELD_INV: {
if (d < 0.1) rs = 0;
break;
private int toRedstoneStrength(double value, double maxValue, ComparatorMode comparatorMode) {
if (maxValue == 0) {
return 0;
}
double proportion = value / maxValue;
int redstoneStrength = (int) (proportion * 15D);
switch (comparatorMode) {
case FIELD_CHARGE, FIELD_CHARGE_INVERTED -> {
if (proportion < 0.1) {
redstoneStrength = 0;
}
}
case IReactorPart.RMODE_FUEL:
case IReactorPart.RMODE_FUEL_INV: {
if (d > 0.9) rs = 15;
break;
case CONVERTED_FUEL, CONVERTED_FUEL_INVERTED -> {
if (proportion > 0.9) {
redstoneStrength = 15;
}
}
}
return rs;
return redstoneStrength;
}
@Override
@SideOnly(Side.CLIENT)
public void receiveObjectFromServer(int index, Object object) {
switch (index) {
case 0:
isStructureValid = (Boolean) object;
break;
// case 1: isActive = (Boolean) object; break;
case 2:
startupInitialized = (Boolean) object;
break;
case 3:
reactorState = (Integer) object;
break;
case 4:
reactorFuel = (Integer) object;
break;
case 5:
convertedFuel = (Integer) object;
break;
case 6:
energySaturation = (Integer) object;
break;
case 7:
maxEnergySaturation = (Integer) object;
break;
case 8:
reactionTemperature = (Double) object;
break;
case 9:
maxReactTemperature = (Double) object;
break;
case 10:
fieldCharge = (Double) object;
break;
case 11:
maxFieldCharge = (Double) object;
break;
case 100:
FMLClientHandler.instance().getClient().effectRenderer.addEffect(
new Particles.ReactorExplosionParticle(worldObj, xCoord, yCoord, zCoord, (Integer) object));
case 0 -> isStructureValid = (boolean) object;
case 2 -> startupInitialized = (boolean) object;
case 3 -> reactorState = ReactorState.getState((int) object);
case 4 -> reactorFuel = (int) object;
case 5 -> convertedFuel = (int) object;
case 6 -> energySaturation = (int) object;
case 7 -> maxEnergySaturation = (int) object;
case 8 -> reactionTemperature = (double) object;
case 9 -> maxReactTemperature = (double) object;
case 10 -> fieldCharge = (double) object;
case 11 -> maxFieldCharge = (double) object;
case 100 -> FMLClientHandler.instance().getClient().effectRenderer
.addEffect(new Particles.ReactorExplosionParticle(worldObj, xCoord, yCoord, zCoord, (int) object));
}
super.receiveObjectFromServer(index, object);
}
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox() {
return INFINITE_EXTENT_AABB;
}
@@ -608,10 +579,9 @@ public class TileReactorCore extends TileObjectSync {
}
if (stabilizerList.tagCount() > 0) compound.setTag("Stabilizers", stabilizerList);
compound.setByte("State", (byte) reactorState);
compound.setByte("State", (byte) reactorState.ordinal());
compound.setBoolean("isStructureValid", isStructureValid);
compound.setBoolean("startupInitialized", startupInitialized);
// compound.setBoolean("isActive", isActive);
compound.setInteger("energySaturation", energySaturation);
compound.setInteger("maxEnergySaturation", maxEnergySaturation);
compound.setInteger("reactorFuel", reactorFuel);
@@ -626,7 +596,7 @@ public class TileReactorCore extends TileObjectSync {
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
stabilizerLocations = new ArrayList<TileLocation>();
stabilizerLocations = new ArrayList<>();
if (compound.hasKey("Stabilizers")) {
NBTTagList stabilizerList = compound.getTagList("Stabilizers", 10);
for (int i = 0; i < stabilizerList.tagCount(); i++) {
@@ -636,10 +606,9 @@ public class TileReactorCore extends TileObjectSync {
}
}
reactorState = compound.getByte("State");
reactorState = ReactorState.getState(compound.getByte("State"));
isStructureValid = compound.getBoolean("isStructureValid");
startupInitialized = compound.getBoolean("startupInitialized");
// isActive = compound.getBoolean("isActive");
energySaturation = compound.getInteger("energySaturation");
maxEnergySaturation = compound.getInteger("maxEnergySaturation");
reactorFuel = compound.getInteger("reactorFuel");
@@ -649,4 +618,52 @@ public class TileReactorCore extends TileObjectSync {
fieldCharge = compound.getDouble("fieldCharge");
maxFieldCharge = compound.getDouble("maxFieldCharge");
}
public Object[] callMethod(String methodName, Object... args) {
if (args.length > 0) {
throw new IllegalArgumentException("This method does not accept arguments");
}
if (methodName.equals("getReactorInfo")) {
Map<Object, Object> map = new HashMap<>();
map.put("temperature", Utills.round(reactionTemperature, 100));
map.put("fieldStrength", Utills.round(fieldCharge, 100));
map.put("maxFieldStrength", Utills.round(maxFieldCharge, 100));
map.put("energySaturation", energySaturation);
map.put("maxEnergySaturation", maxEnergySaturation);
map.put("fuelConversion", Utills.round(convertedFuel + conversionUnit, 1000));
map.put("maxFuelConversion", reactorFuel + convertedFuel);
map.put("generationRate", (int) generationRate);
map.put("fieldDrainRate", fieldDrain);
map.put("fuelConversionRate", (int) Math.round(fuelUseRate * 1000000D));
if (reactorState == ReactorState.STARTING) {
map.put("status", canStart() ? "charged" : "charging");
} else {
map.put("status", reactorState.name().toLowerCase());
}
return new Object[] { map };
}
if (methodName.equals("chargeReactor")) {
if (canCharge()) {
reactorState = ReactorState.STARTING;
return new Object[] { true };
}
return new Object[] { false };
}
if (methodName.equals("activateReactor")) {
if (canStart()) {
reactorState = ReactorState.ONLINE;
return new Object[] { true };
}
return new Object[] { false };
}
if (methodName.equals("stopReactor")) {
if (canStop()) {
reactorState = ReactorState.STOPPING;
return new Object[] { true };
}
return new Object[] { false };
}
return new Object[] {};
}
}
@@ -1,22 +1,17 @@
package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.brandonscore.common.utills.Utills;
import com.brandon3055.draconicevolution.DraconicEvolution;
import com.brandon3055.draconicevolution.client.render.particle.ParticleReactorBeam;
import com.brandon3055.draconicevolution.common.blocks.multiblock.IReactorPart;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation;
import com.brandon3055.draconicevolution.integration.computers.IDEPeripheral;
import cofh.api.energy.IEnergyReceiver;
@@ -29,31 +24,29 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileReactorEnergyInjector extends TileEntity implements IReactorPart, IEnergyReceiver, IDEPeripheral {
public float modelIllumination = 1F;
public int facingDirection = ForgeDirection.UP.ordinal();
public MultiblockHelper.TileLocation masterLocation = new MultiblockHelper.TileLocation();
public ForgeDirection facing = ForgeDirection.UP;
public TileLocation masterLocation = new TileLocation();
public boolean isValid = false;
public int tick = 0;
@SideOnly(Side.CLIENT)
private ParticleReactorBeam beam;
private TileReactorCore core = null;
private int redstoneMode = 0;
private int rs = -1;
private int rsCach = -1;
private ComparatorMode comparatorMode = ComparatorMode.TEMPERATURE;
private int comparatorOutputCache = -1;
@Override
public void updateEntity() {
if (worldObj.isRemote && isValid) {
updateBeam();
return;
}
TileEntity master = masterLocation.getTileEntity(worldObj);
if (!worldObj.isRemote && master instanceof TileReactorCore) {
rs = ((TileReactorCore) master).getComparatorOutput(redstoneMode);
if (rs != rsCach) {
rsCach = rs;
Utills.updateNeabourBlocks(worldObj, xCoord, yCoord, zCoord);
TileReactorCore core = getMaster();
if (core != null) {
int comparatorOutput = core.getComparatorOutput(comparatorMode);
if (comparatorOutput != comparatorOutputCache) {
comparatorOutputCache = comparatorOutput;
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
}
}
}
@@ -64,30 +57,42 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
}
public void onPlaced() {
checkForMaster();
}
public boolean checkForMaster() {
for (int i = 1; i < 10; i++) {
ForgeDirection dir = ForgeDirection.getOrientation(facingDirection);
int x = xCoord + (dir.offsetX * i);
int y = yCoord + (dir.offsetY * i);
int z = zCoord + (dir.offsetZ * i);
if (!worldObj.isAirBlock(x, y, z)) {
TileEntity tile = worldObj.getTileEntity(x, y, z);
if (tile instanceof TileReactorCore) {
masterLocation.set(x, y, z);
isValid = true;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return true;
} else {
isValid = false;
return false;
}
for (int distance = 1; distance <= TileReactorCore.MAXIMUM_PART_DISTANCE; distance++) {
int targetX = xCoord + facing.offsetX * distance;
int targetY = yCoord + facing.offsetY * distance;
int targetZ = zCoord + facing.offsetZ * distance;
TileEntity tile = worldObj.getTileEntity(targetX, targetY, targetZ);
if (tile instanceof TileReactorCore) {
setUp(new TileLocation(targetX, targetY, targetZ));
return;
}
}
shutDown();
}
@Override
public TileLocation getMasterLocation() {
return masterLocation;
}
@Override
public TileReactorCore getMaster() {
TileEntity tile = masterLocation.getTileEntity(worldObj);
return tile instanceof TileReactorCore core ? core : null;
}
@Override
public void setUp(TileLocation masterLocation) {
this.masterLocation = masterLocation;
isValid = true;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public void shutDown() {
masterLocation = new TileLocation();
isValid = false;
return false;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
@@ -96,33 +101,25 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
}
@Override
public String getRedstoneModeString() {
return StatCollector.translateToLocal("msg.de.reactorRSMode." + redstoneMode + ".txt");
public ForgeDirection getFacing() {
return facing;
}
@Override
public void changeRedstoneMode() {
if (redstoneMode == IReactorPart.RMODE_FUEL_INV) redstoneMode = 0;
else redstoneMode++;
public ComparatorMode getComparatorMode() {
return comparatorMode;
}
@Override
public int getRedstoneMode() {
return redstoneMode;
}
@Override
public void shutDown() {
masterLocation = new MultiblockHelper.TileLocation();
isValid = false;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
public void changeComparatorMode() {
comparatorMode = comparatorMode.next();
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound compound = new NBTTagCompound();
masterLocation.writeToNBT(compound, "Master");
compound.setInteger("Facing", facingDirection);
compound.setInteger("Facing", facing.ordinal());
compound.setBoolean("IsValid", isValid);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, compound);
}
@@ -131,41 +128,27 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
NBTTagCompound compound = pkt.func_148857_g();
masterLocation.readFromNBT(compound, "Master");
facingDirection = compound.getInteger("Facing");
facing = ForgeDirection.getOrientation(compound.getInteger("Facing"));
isValid = compound.getBoolean("IsValid");
super.onDataPacket(net, pkt);
}
public TileReactorCore getCore() {
if (core == null || core.isInvalid()) {
if (getMaster().getTileEntity(worldObj) instanceof TileReactorCore)
core = (TileReactorCore) getMaster().getTileEntity(worldObj);
else core = null;
}
return core;
}
@Override
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
masterLocation.writeToNBT(compound, "Master");
compound.setInteger("Facing", facingDirection);
compound.setInteger("Facing", facing.ordinal());
compound.setBoolean("IsValid", isValid);
compound.setInteger("RedstoneMode", redstoneMode);
compound.setInteger("RedstoneMode", comparatorMode.ordinal());
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
masterLocation.readFromNBT(compound, "Master");
facingDirection = compound.getInteger("Facing");
facing = ForgeDirection.getOrientation(compound.getInteger("Facing"));
isValid = compound.getBoolean("IsValid");
redstoneMode = compound.getInteger("RedstoneMode");
}
@Override
public MultiblockHelper.TileLocation getMaster() {
return masterLocation;
comparatorMode = ComparatorMode.getMode(compound.getInteger("RedstoneMode"));
}
@Override
@@ -175,8 +158,13 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
if (simulate) return Integer.MAX_VALUE;
else if (getCore() != null) return getCore().injectEnergy(maxReceive);
if (simulate) {
return Integer.MAX_VALUE;
}
TileReactorCore core = getMaster();
if (core != null) {
return core.injectEnergy(maxReceive);
}
return 0;
}
@@ -192,7 +180,7 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return from == ForgeDirection.getOrientation(facingDirection).getOpposite();
return from == facing.getOpposite();
}
@Override
@@ -206,48 +194,8 @@ public class TileReactorEnergyInjector extends TileEntity implements IReactorPar
}
@Override
public Object[] callMethod(String method, Object... args) {
if (!(getMaster().getTileEntity(worldObj) instanceof TileReactorCore)) return null;
TileReactorCore reactor = (TileReactorCore) getMaster().getTileEntity(worldObj);
if (args.length > 0) throw new IllegalArgumentException("This method dose not accept arguments");
if (method.equals("getReactorInfo")) {
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("temperature", Utills.round(reactor.reactionTemperature, 100));
map.put("fieldStrength", Utills.round(reactor.fieldCharge, 100));
map.put("maxFieldStrength", Utills.round(reactor.maxFieldCharge, 100));
map.put("energySaturation", reactor.energySaturation);
map.put("maxEnergySaturation", reactor.maxEnergySaturation);
map.put("fuelConversion", Utills.round((double) reactor.convertedFuel + reactor.conversionUnit, 1000));
map.put("maxFuelConversion", reactor.reactorFuel + reactor.convertedFuel);
map.put("generationRate", (int) reactor.generationRate);
map.put("fieldDrainRate", reactor.fieldDrain);
map.put("fuelConversionRate", (int) Math.round(reactor.fuelUseRate * 1000000D));
map.put(
"status",
reactor.reactorState == 0 ? "offline"
: reactor.reactorState == 1 && !reactor.canStart() ? "charging"
: reactor.reactorState == 1 && reactor.canStart() ? "charged"
: reactor.reactorState == 2 ? "online"
: reactor.reactorState == 3 ? "stopping" : "invalid");
return new Object[] { map };
} else if (method.equals("chargeReactor")) {
if (reactor.canCharge()) {
reactor.reactorState = TileReactorCore.STATE_START;
return new Object[] { true };
} else return new Object[] { false };
} else if (method.equals("activateReactor")) {
if (reactor.canStart()) {
reactor.reactorState = TileReactorCore.STATE_ONLINE;
return new Object[] { true };
} else return new Object[] { false };
} else if (method.equals("stopReactor")) {
if (reactor.canStop()) {
reactor.reactorState = TileReactorCore.STATE_STOP;
return new Object[] { true };
} else return new Object[] { false };
}
return new Object[] {};
public Object[] callMethod(String methodName, Object... args) {
TileReactorCore core = getMaster();
return core != null ? core.callMethod(methodName, args) : null;
}
}
@@ -1,21 +1,17 @@
package com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.brandonscore.common.utills.Utills;
import com.brandon3055.draconicevolution.DraconicEvolution;
import com.brandon3055.draconicevolution.client.render.particle.ParticleReactorBeam;
import com.brandon3055.draconicevolution.common.blocks.multiblock.IReactorPart;
import com.brandon3055.draconicevolution.common.blocks.multiblock.MultiblockHelper.TileLocation;
import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.reactor.TileReactorCore.ReactorState;
import com.brandon3055.draconicevolution.integration.computers.IDEPeripheral;
import cofh.api.energy.IEnergyProvider;
@@ -33,136 +29,101 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
public float coreSpeed = 1F;
public float ringSpeed = 1F;
public float modelIllumination = 0F;
public int facingDirection = ForgeDirection.UP.ordinal();
public ForgeDirection facing = ForgeDirection.UP;
public TileLocation masterLocation = new TileLocation();
public boolean isValid = false;
public int tick = 0;
private int redstoneMode = 0;
private ComparatorMode comparatorMode = ComparatorMode.TEMPERATURE;
private int comparatorOutputCache = -1;
@SideOnly(Side.CLIENT)
private ParticleReactorBeam beam;
private int rs = -1;
private int rsCach = -1;
@Override
public void updateEntity() {
tick++;
if (worldObj.isRemote) {
updateBeam();
return;
}
TileEntity master = masterLocation.getTileEntity(worldObj);
if (master instanceof TileReactorCore
&& ((TileReactorCore) master).reactorState == TileReactorCore.STATE_ONLINE) {
ForgeDirection back = ForgeDirection.getOrientation(facingDirection).getOpposite();
TileEntity output = worldObj
.getTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ);
if (output instanceof IEnergyReceiver) {
int sent = ((IEnergyReceiver) output).receiveEnergy(
back.getOpposite(),
Math.min(
((TileReactorCore) master).energySaturation,
((TileReactorCore) master).maxEnergySaturation / 100),
false);
((TileReactorCore) master).energySaturation -= sent;
TileReactorCore core = getMaster();
if (core != null) {
if (core.reactorState == ReactorState.ONLINE) {
ForgeDirection back = facing.getOpposite();
TileEntity tile = worldObj
.getTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ);
if (tile instanceof IEnergyReceiver receiver) {
int energyToReceive = Math.min(core.energySaturation, core.maxEnergySaturation / 100);
int energyReceived = receiver.receiveEnergy(facing, energyToReceive, false);
core.energySaturation -= energyReceived;
}
}
}
if (!worldObj.isRemote && master instanceof TileReactorCore) {
rs = ((TileReactorCore) master).getComparatorOutput(redstoneMode);
if (rs != rsCach) {
rsCach = rs;
Utills.updateNeabourBlocks(worldObj, xCoord, yCoord, zCoord);
int comparatorOutput = core.getComparatorOutput(comparatorMode);
if (comparatorOutput != comparatorOutputCache) {
comparatorOutputCache = comparatorOutput;
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, blockType);
}
}
}
@SideOnly(Side.CLIENT)
private void updateBeam() {
if (worldObj.isRemote) {
if (!(masterLocation.getTileEntity(worldObj) instanceof TileReactorCore)) {
coreSpeed = 0;
ringSpeed = 0;
modelIllumination = 0;
return;
}
TileReactorCore core = (TileReactorCore) masterLocation.getTileEntity(worldObj);
coreRotation += coreSpeed;
ringRotation += ringSpeed;
coreSpeed = 30F * core.renderSpeed;
ringSpeed = 5F * core.renderSpeed;
modelIllumination = core.renderSpeed;
if (tick % 100 == 0) beam = null;
if (isValid) beam = DraconicEvolution.proxy.reactorBeam(this, beam, true);
TileReactorCore core = getMaster();
if (core == null) {
coreSpeed = 0;
ringSpeed = 0;
modelIllumination = 0;
return;
}
coreRotation += coreSpeed;
ringRotation += ringSpeed;
coreSpeed = 30F * core.renderSpeed;
ringSpeed = 5F * core.renderSpeed;
modelIllumination = core.renderSpeed;
if (tick % 100 == 0) {
beam = null;
}
if (isValid) {
beam = DraconicEvolution.proxy.reactorBeam(this, beam, true);
}
}
public void onPlaced() {
checkForMaster();
}
public void onBroken() {}
public boolean checkForMaster() {
for (int i = 1; i < 10; i++) {
ForgeDirection dir = ForgeDirection.getOrientation(facingDirection);
int x = xCoord + (dir.offsetX * i);
int y = yCoord + (dir.offsetY * i);
int z = zCoord + (dir.offsetZ * i);
if (!worldObj.isAirBlock(x, y, z)) {
TileEntity tile = worldObj.getTileEntity(x, y, z);
if (tile instanceof TileReactorCore && ((TileReactorCore) tile).stabilizerLocations.size() < 4) // todo
// add
// check
// reactor
// side
// to
// make
// sure
// this
// aligns
// with
// other
// stabilizers
{
((TileReactorCore) tile).stabilizerLocations.add(new TileLocation(xCoord, yCoord, zCoord));
masterLocation.set(x, y, z);
isValid = true;
((TileReactorCore) tile).validateStructure();
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
return true;
} else {
isValid = false;
return false;
}
for (int distance = 1; distance <= TileReactorCore.MAXIMUM_PART_DISTANCE; distance++) {
TileLocation location = new TileLocation(
xCoord + facing.offsetX * distance,
yCoord + facing.offsetY * distance,
zCoord + facing.offsetZ * distance);
TileEntity tile = location.getTileEntity(worldObj);
if (tile instanceof TileReactorCore core) {
setUp(location);
core.updateReactorParts(false);
core.validateStructure();
return;
}
}
isValid = false;
return false;
shutDown();
}
@Override
public boolean isActive() {
return isValid;
public TileLocation getMasterLocation() {
return masterLocation;
}
@Override
public String getRedstoneModeString() {
return StatCollector.translateToLocal("msg.de.reactorRSMode." + redstoneMode + ".txt");
public TileReactorCore getMaster() {
TileEntity tile = masterLocation.getTileEntity(worldObj);
return tile instanceof TileReactorCore core ? core : null;
}
@Override
public void changeRedstoneMode() {
if (redstoneMode == IReactorPart.RMODE_FUEL_INV) redstoneMode = 0;
else redstoneMode++;
}
@Override
public int getRedstoneMode() {
return redstoneMode;
public void setUp(TileLocation masterLocation) {
this.masterLocation = masterLocation;
isValid = true;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
@@ -172,11 +133,31 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public boolean isActive() {
return isValid;
}
@Override
public ForgeDirection getFacing() {
return facing;
}
@Override
public ComparatorMode getComparatorMode() {
return comparatorMode;
}
@Override
public void changeComparatorMode() {
comparatorMode = comparatorMode.next();
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound compound = new NBTTagCompound();
masterLocation.writeToNBT(compound, "Master");
compound.setInteger("Facing", facingDirection);
compound.setInteger("Facing", facing.ordinal());
compound.setBoolean("IsValid", isValid);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, compound);
}
@@ -185,7 +166,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
NBTTagCompound compound = pkt.func_148857_g();
masterLocation.readFromNBT(compound, "Master");
facingDirection = compound.getInteger("Facing");
facing = ForgeDirection.getOrientation(compound.getInteger("Facing"));
isValid = compound.getBoolean("IsValid");
super.onDataPacket(net, pkt);
}
@@ -194,23 +175,18 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
masterLocation.writeToNBT(compound, "Master");
compound.setInteger("Facing", facingDirection);
compound.setInteger("Facing", facing.ordinal());
compound.setBoolean("IsValid", isValid);
compound.setInteger("RedstoneMode", redstoneMode);
compound.setInteger("RedstoneMode", comparatorMode.ordinal());
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
masterLocation.readFromNBT(compound, "Master");
facingDirection = compound.getInteger("Facing");
facing = ForgeDirection.getOrientation(compound.getInteger("Facing"));
isValid = compound.getBoolean("IsValid");
redstoneMode = compound.getInteger("RedstoneMode");
}
@Override
public TileLocation getMaster() {
return masterLocation;
comparatorMode = ComparatorMode.getMode(compound.getInteger("RedstoneMode"));
}
@Override
@@ -230,7 +206,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
@Override
public boolean canConnectEnergy(ForgeDirection from) {
return from == ForgeDirection.getOrientation(facingDirection).getOpposite();
return from == facing.getOpposite();
}
@Override
@@ -249,48 +225,8 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I
}
@Override
public Object[] callMethod(String method, Object... args) {
if (!(getMaster().getTileEntity(worldObj) instanceof TileReactorCore)) return null;
TileReactorCore reactor = (TileReactorCore) getMaster().getTileEntity(worldObj);
if (args.length > 0) throw new IllegalArgumentException("This method dose not accept arguments");
if (method.equals("getReactorInfo")) {
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("temperature", Utills.round(reactor.reactionTemperature, 100));
map.put("fieldStrength", Utills.round(reactor.fieldCharge, 100));
map.put("maxFieldStrength", Utills.round(reactor.maxFieldCharge, 100));
map.put("energySaturation", reactor.energySaturation);
map.put("maxEnergySaturation", reactor.maxEnergySaturation);
map.put("fuelConversion", Utills.round((double) reactor.convertedFuel + reactor.conversionUnit, 1000));
map.put("maxFuelConversion", reactor.reactorFuel + reactor.convertedFuel);
map.put("generationRate", (int) reactor.generationRate);
map.put("fieldDrainRate", reactor.fieldDrain);
map.put("fuelConversionRate", (int) Math.round(reactor.fuelUseRate * 1000000D));
map.put(
"status",
reactor.reactorState == 0 ? "offline"
: reactor.reactorState == 1 && !reactor.canStart() ? "charging"
: reactor.reactorState == 1 && reactor.canStart() ? "charged"
: reactor.reactorState == 2 ? "online"
: reactor.reactorState == 3 ? "stopping" : "invalid");
return new Object[] { map };
} else if (method.equals("chargeReactor")) {
if (reactor.canCharge()) {
reactor.reactorState = TileReactorCore.STATE_START;
return new Object[] { true };
} else return new Object[] { false };
} else if (method.equals("activateReactor")) {
if (reactor.canStart()) {
reactor.reactorState = TileReactorCore.STATE_ONLINE;
return new Object[] { true };
} else return new Object[] { false };
} else if (method.equals("stopReactor")) {
if (reactor.canStop()) {
reactor.reactorState = TileReactorCore.STATE_STOP;
return new Object[] { true };
} else return new Object[] { false };
}
return new Object[] {};
public Object[] callMethod(String methodName, Object... args) {
TileReactorCore core = getMaster();
return core != null ? core.callMethod(methodName, args) : null;
}
}
@@ -0,0 +1,16 @@
package com.brandon3055.draconicevolution.common.utills;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class OreDictionaryHelper {
public static Set<String> getOreNames(ItemStack stack) {
int[] oreIds = OreDictionary.getOreIDs(stack);
return Arrays.stream(oreIds).mapToObj(OreDictionary::getOreName).collect(Collectors.toSet());
}
}
@@ -2,8 +2,8 @@ package com.brandon3055.draconicevolution.common.utills;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.util.ForgeDirection;
import com.brandon3055.draconicevolution.common.ModBlocks;
@@ -15,7 +15,7 @@ import com.brandon3055.draconicevolution.common.tileentities.multiblocktiles.Til
*/
public class PortalHelper {
static int iterationNow = 0;
public static final int MAXIMUM_PORTAL_SIZE = 150;
public static boolean isFrame(Block block) {
return block == ModBlocks.infusedObsidian;
@@ -30,13 +30,17 @@ public class PortalHelper {
}
public static PortalStructure getValidStructure(World world, int x, int y, int z) {
if (world.isRemote) return null;
if (world.isRemote) {
return null;
}
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
for (ForgeDirection plane : ForgeDirection.VALID_DIRECTIONS) {
if (plane != direction && plane != direction.getOpposite()) {
PortalStructure structure = traceFrame(world, x, y, z, direction, plane);
if (structure != null && structure.scanPortal(world, x, y, z, false, false)) return structure;
if (structure != null && structure.scanPortal(world, x, y, z, false, false)) {
return structure;
}
}
}
}
@@ -46,67 +50,45 @@ public class PortalHelper {
public static PortalStructure traceFrame(World world, int x, int y, int z, ForgeDirection startDir,
ForgeDirection plane) {
int MAX_SIZE = 150;
int startX = x + startDir.offsetX;
int startY = y + startDir.offsetY;
int startZ = z + startDir.offsetZ;
// Check that the trace is starting from a receptacle
if (!world.isAirBlock(startX, startY, startZ)) return null;
int xSize = 0;
int ySize = 0;
int yOffset = 0;
// Get X size
for (int i = 0; i <= MAX_SIZE; i++) {
Block block = world.getBlock(
startX + i * startDir.offsetX,
startY + i * startDir.offsetY,
startZ + i * startDir.offsetZ);
if (isFrame(block)) {
xSize = i;
break;
} else if (!world.isAirBlock(
startX + i * startDir.offsetX,
startY + i * startDir.offsetY,
startZ + i * startDir.offsetZ))
return null;
if (!world.isAirBlock(startX, startY, startZ)) {
return null;
}
// Get Y size above receptacle
for (int i = 0; i <= MAX_SIZE; i++) {
Block block = world
.getBlock(startX + i * plane.offsetX, startY + i * plane.offsetY, startZ + i * plane.offsetZ);
if (isFrame(block)) {
ySize = i;
break;
} else if (!world
.isAirBlock(startX + i * plane.offsetX, startY + i * plane.offsetY, startZ + i * plane.offsetZ))
return null;
}
int xSize = findDistanceToFrame(world, startX, startY, startZ, startDir);
int ySize = findDistanceToFrame(world, startX, startY, startZ, plane);
int yOffset = findDistanceToFrame(world, startX, startY, startZ, plane.getOpposite());
ySize += yOffset - 1;
// Get Y size below receptacle and get y offset
for (int i = 0; i <= MAX_SIZE; i++) {
Block block = world
.getBlock(startX - i * plane.offsetX, startY - i * plane.offsetY, startZ - i * plane.offsetZ);
if (isFrame(block)) {
ySize += i - 1;
yOffset = i;
break;
} else if (!world
.isAirBlock(startX - i * plane.offsetX, startY - i * plane.offsetY, startZ - i * plane.offsetZ))
return null;
if (xSize == 0 || ySize == 0 || yOffset == 0 || ySize > PortalHelper.MAXIMUM_PORTAL_SIZE) {
return null;
}
if (xSize == 0 || ySize == 0 || ySize > MAX_SIZE) return null;
PortalStructure structure = new PortalStructure(xSize, ySize, yOffset, startDir, plane);
if (structure.checkFrameIsValid(world, x, y, z) && structure.scanPortal(world, x, y, z, false, false)) {
return structure;
}
return null;
if (!structure.checkFrameIsValid(world, x, y, z) || !structure.scanPortal(world, x, y, z, false, false))
return null;
}
return structure;
private static int findDistanceToFrame(World world, int startX, int startY, int startZ, ForgeDirection direction) {
for (int distance = 1; distance <= PortalHelper.MAXIMUM_PORTAL_SIZE; distance++) {
int targetX = startX + direction.offsetX * distance;
int targetY = startY + direction.offsetY * distance;
int targetZ = startZ + direction.offsetZ * distance;
Block block = world.getBlock(targetX, targetY, targetZ);
if (isFrame(block)) {
return distance;
}
if (!world.isAirBlock(targetX, targetY, targetZ)) {
return 0;
}
}
return 0;
}
public static class PortalStructure {
@@ -128,77 +110,66 @@ public class PortalHelper {
}
public boolean checkFrameIsValid(World world, int x, int y, int z) {
int startX = x + startDir.offsetX;
int startY = y + startDir.offsetY;
int startZ = z + startDir.offsetZ;
// Check structure for y size
for (int y1 = 1; y1 <= ySize; y1++) {
int y2 = y1 - yOffset;
int inX = startX + y2 * plane.offsetX - startDir.offsetX;
int inY = startY + y2 * plane.offsetY - startDir.offsetY;
int inZ = startZ + y2 * plane.offsetZ - startDir.offsetZ;
int outX = startX + y2 * plane.offsetX + (xSize) * startDir.offsetX;
int outY = startY + y2 * plane.offsetY + (xSize) * startDir.offsetY;
int outZ = startZ + y2 * plane.offsetZ + (xSize) * startDir.offsetZ;
if (!isFrame(world.getBlock(inX, inY, inZ)) && !(inX == x && inY == y && inZ == z)) return false;
if (!isFrame(world.getBlock(outX, outY, outZ))) return false;
for (int xDistance = 1; xDistance <= xSize; xDistance++) {
if (isFrameMissing(world, x, y, z, xDistance, -yOffset)
|| isFrameMissing(world, x, y, z, xDistance, ySize - yOffset + 1)) {
return false;
}
}
// Check structure for x size
for (int x1 = 0; x1 < xSize; x1++) {
int upX = startX + x1 * startDir.offsetX - yOffset * plane.offsetX;
int upY = startY + x1 * startDir.offsetY - yOffset * plane.offsetY;
int upZ = startZ + x1 * startDir.offsetZ - yOffset * plane.offsetZ;
int downX = startX + x1 * startDir.offsetX + (ySize - yOffset + 1) * plane.offsetX;
int downY = startY + x1 * startDir.offsetY + (ySize - yOffset + 1) * plane.offsetY;
int downZ = startZ + x1 * startDir.offsetZ + (ySize - yOffset + 1) * plane.offsetZ;
if (!isFrame(world.getBlock(upX, upY, upZ))) return false;
if (!isFrame(world.getBlock(downX, downY, downZ))) return false;
for (int yDistance = 1 - yOffset; yDistance <= ySize - yOffset; yDistance++) {
if (yDistance != 0 && isFrameMissing(world, x, y, z, 0, yDistance)
|| isFrameMissing(world, x, y, z, xSize + 1, yDistance)) {
return false;
}
}
return true;
}
private boolean isFrameMissing(World world, int x, int y, int z, int xDistance, int yDistance) {
int targetX = x + startDir.offsetX * xDistance + plane.offsetX * yDistance;
int targetY = y + startDir.offsetY * xDistance + plane.offsetY * yDistance;
int targetZ = z + startDir.offsetZ * xDistance + plane.offsetZ * yDistance;
return !isFrame(world.getBlock(targetX, targetY, targetZ));
}
public boolean scanPortal(World world, int x, int y, int z, boolean setPortalBlocks,
boolean checkPortalBlocks) {
int startX = x + startDir.offsetX;
int startY = y + startDir.offsetY;
int startZ = z + startDir.offsetZ;
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileDislocatorReceptacle receptacle)) {
return false;
}
if (setPortalBlocks) {
receptacle.updating = true;
}
TileDislocatorReceptacle receptacle = (TileDislocatorReceptacle) world.getTileEntity(x, y, z);
if (receptacle == null) return false;
if (setPortalBlocks) receptacle.updating = true;
for (int x1 = 0; x1 < xSize; x1++) {
for (int y1 = 1; y1 <= ySize; y1++) {
int y2 = y1 - yOffset;
int X = (startX + x1 * startDir.offsetX) + y2 * plane.offsetX;
int Y = (startY + x1 * startDir.offsetY) + y2 * plane.offsetY;
int Z = (startZ + x1 * startDir.offsetZ) + y2 * plane.offsetZ;
Block block = world.getBlock(X, Y, Z);
for (int xDistance = 1; xDistance <= xSize; xDistance++) {
for (int yDistance = 1 - yOffset; yDistance <= ySize - yOffset; yDistance++) {
int targetX = x + xDistance * startDir.offsetX + yDistance * plane.offsetX;
int targetY = y + xDistance * startDir.offsetY + yDistance * plane.offsetY;
int targetZ = z + xDistance * startDir.offsetZ + yDistance * plane.offsetZ;
Block block = world.getBlock(targetX, targetY, targetZ);
if (checkPortalBlocks) {
if (!isPortal(block)) return false;
if (!isPortal(block)) {
return false;
}
} else if (setPortalBlocks) {
world.setBlock(X, Y, Z, ModBlocks.portal);
Chunk chunk = world.getChunkFromBlockCoords(X, Z);
TilePortalBlock tile = (TilePortalBlock) chunk.func_150806_e(X & 15, Y, Z & 15);
tile.masterX = x;
tile.masterY = y;
tile.masterZ = z;
} else if (!world.isAirBlock(X, Y, Z)) return false;
world.setBlock(targetX, targetY, targetZ, ModBlocks.portal);
tile = world.getTileEntity(targetX, targetY, targetZ);
if (tile instanceof TilePortalBlock portal) {
portal.masterX = x;
portal.masterY = y;
portal.masterZ = z;
}
} else if (!world.isAirBlock(targetX, targetY, targetZ)) {
return false;
}
}
}
if (setPortalBlocks) receptacle.updating = false;
if (setPortalBlocks) {
receptacle.updating = false;
}
return true;
}
@@ -382,6 +382,7 @@ achievement.draconicevolution.manual=Knowledge to the Max!
achievement.draconicevolution.manual.desc=Craft the Draconic Tablet
//InfoHelper ----------------------------------------------------------------------------------------------------------------------------------------
info.de.tier.txt=Tier
info.de.charge.txt=Charge
info.de.hold.txt=Hold
info.de.shift.txt=Shift
@@ -526,6 +527,50 @@ gui.de.genRate.name=Generation Rate
gui.de.fieldInputRate.name=Field Input Rate
gui.de.fuelConversion.name=Fuel Conversion Rate
gui.de.particleGenerator.random.name=Random:
gui.de.particleGenerator.red.name=Red:
gui.de.particleGenerator.green.name=Green:
gui.de.particleGenerator.blue.name=Blue:
gui.de.particleGenerator.motionX.name=Motion X:
gui.de.particleGenerator.motionY.name=Motion Y:
gui.de.particleGenerator.motionZ.name=Motion Z:
gui.de.particleGenerator.scale.name=Scale:
gui.de.particleGenerator.life.name=Life (T):
gui.de.particleGenerator.spawnX.name=Spawn X:
gui.de.particleGenerator.spawnY.name=Spawn Y:
gui.de.particleGenerator.spawnZ.name=Spawn Z:
gui.de.particleGenerator.delay.name=Delay:
gui.de.particleGenerator.fade.name=Fade:
gui.de.particleGenerator.gravity.name=Gravity:
gui.de.particleGenerator.pitch.name=Pitch:
gui.de.particleGenerator.yaw.name=Yaw:
gui.de.particleGenerator.rotation.name=Rotation:
gui.de.particleGenerator.length.name=Length:
gui.de.particleGenerator.main.title=Particle Generator
gui.de.particleGenerator.beam.title=Beam Generator
gui.de.particleGenerator.info.title=Information
gui.de.particleGenerator.hold.name=Hold:
gui.de.particleGenerator.info.name=i
gui.de.particleGenerator.back.name=Back
gui.de.particleGenerator.page.name=Page: %d
gui.de.particleGenerator.blockCollision.name=Block Collision: %s
gui.de.particleGenerator.particleSelected.name=Particle Selected: %d
gui.de.particleGenerator.enabled.name=Enabled: %s
gui.de.particleGenerator.renderCore.name=Render Core: %s
gui.de.particleGenerator.saveSettings.name=Take note of values
gui.de.particleGenerator.info.1= The Particle Generator is a decorative device that allows you to create your own custom particle effects.\n It is fairly easy you use this device you simply adjust the fields (variables) in the interface to change how the generated particles look and behave.\n This block is a work in progress and new features and particles are likely to be added in future versions.\n The following is a list of all of the fields in the interface and what they do.
gui.de.particleGenerator.info.2= The first thing to note is that most fields have a random modifier which will add a random number between 0 and whatever max (or min) value you give it to the field.\n - The first 3 fields (Red, Green & Blue) control the colour of the particle. Most people should be familiar with this colour system if not google RGB colours. Note: the max value for each colour can not go higher then 255 so the colour field limits the random modifier e.g. if the colour field is set to 255 and the random modifier is set to 20 the result will always be 255.
gui.de.particleGenerator.info.3= - The next 3 fields (Motion X, Y & Z) control the direction and speed of the particle.\n - The "Life" field sets how long (in ticks) before the particle despawns.\n - The "Scale" field sets the size of the particle.\n - The next 3 fields (Spawn X, Y & Z) Sets the spawn location of the particle (relative to the location of the particle generator).
gui.de.particleGenerator.info.4= - The "Delay" field sets the delay (in ticks) between each particle spawn e.g. 1=20/s, 20=1/s, 100=1/5s.\n - The "Fade" field sets how long (in ticks) it takes the particle to fade out of existance. Note: This adds to the life of the particle.\n - The "Gravity" field sets how the particle is affected by gravity.\n - "Block Collision" Toggles weather or not the particle will collide with blocks.\n - "Particle Selected" switches between the different particles available.
gui.de.particleGenerator.info.5.title=Redstone Control\n\n
gui.de.particleGenerator.info.5= By default a redstone signal is required for the generator to run.\n However if you shift right click the generator with an empty hand it will switch to inverted mode.\n The redstone mode is indicated by the 8 cubes at the corners of the block.
gui.de.particleGenerator.info.6.title=Computer Control\n\n
gui.de.particleGenerator.info.6= The Generator can be controlled via a computer.\n It exposes a relatively straight forward API:\n\n setGeneratorProperty(property, value)\n getGeneratorState()\n resetGeneratorState()
gui.de.particleGenerator.info.7= Generator state is obtained as a whole from getGeneratorState, whereas properties are modified one at a time using setGeneratorProperty. Property names are strings and mostly correspond to button labels in the GUI.
gui.de.insert.txt=Insert
gui.de.extract.txt=Extract
gui.de.fuel.txt=Fuel