Skip to content

Commit

Permalink
Merge pull request #1264 from johalun/1.20.1-thermostat
Browse files Browse the repository at this point in the history
Add thermostat tube module
  • Loading branch information
desht authored Dec 26, 2023
2 parents 5313a58 + 3da99e9 commit b5713e1
Show file tree
Hide file tree
Showing 26 changed files with 1,326 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/api/java/me/desht/pneumaticcraft/api/lib/Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Names {
public static final ResourceLocation MODULE_LOGISTICS = RL("logistics_module");
public static final ResourceLocation MODULE_REDSTONE = RL("redstone_module");
public static final ResourceLocation MODULE_VACUUM = RL("vacuum_module");
public static final ResourceLocation MODULE_THERMOSTAT = RL("thermostat_module");

public static final String PNEUMATIC_KEYBINDING_CATEGORY_MAIN = "key.pneumaticcraft.category.main";
public static final String PNEUMATIC_KEYBINDING_CATEGORY_UPGRADE_TOGGLES = "key.pneumaticcraft.category.upgrade_toggles";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_ingot_iron_compressed": {
"conditions": {
"items": [
{
"items": [
"pneumaticcraft:ingot_iron_compressed"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "pneumaticcraft:thermostat_module"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_ingot_iron_compressed",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"pneumaticcraft:thermostat_module"
]
},
"sends_telemetry_event": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"D": {
"tag": "forge:dusts/redstone"
},
"H": {
"item": "pneumaticcraft:heat_pipe"
},
"M": {
"item": "pneumaticcraft:manometer"
},
"T": {
"item": "pneumaticcraft:pressure_tube"
}
},
"pattern": [
" M ",
" H ",
"TDT"
],
"result": {
"item": "pneumaticcraft:thermostat_module"
},
"show_notification": true
}
4 changes: 4 additions & 0 deletions src/main/java/me/desht/pneumaticcraft/client/ClientSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.desht.pneumaticcraft.client.gui.tubemodule.LogisticsModuleScreen;
import me.desht.pneumaticcraft.client.gui.tubemodule.PressureGaugeModuleScreen;
import me.desht.pneumaticcraft.client.gui.tubemodule.RedstoneModuleScreen;
import me.desht.pneumaticcraft.client.gui.tubemodule.ThermostatModuleScreen;
import me.desht.pneumaticcraft.client.gui.upgrademanager.*;
import me.desht.pneumaticcraft.client.model.ModelMinigun;
import me.desht.pneumaticcraft.client.model.PNCModelLayers;
Expand Down Expand Up @@ -206,6 +207,7 @@ public static void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDe
event.registerLayerDefinition(PNCModelLayers.REGULATOR_MODULE, RegulatorRenderer::createBodyLayer);
event.registerLayerDefinition(PNCModelLayers.SAFETY_VALVE_MODULE, SafetyValveRenderer::createBodyLayer);
event.registerLayerDefinition(PNCModelLayers.VACUUM_MODULE, VacuumRenderer::createBodyLayer);
event.registerLayerDefinition(PNCModelLayers.THERMOSTAT_MODULE, ThermostatRenderer::createBodyLayer);
}

private static void registerItemModelProperties() {
Expand Down Expand Up @@ -416,6 +418,7 @@ private static void registerTubeModuleFactories() {
TubeModuleClientRegistry.registerTubeModuleGUI(Names.MODULE_SAFETY_VALVE, PressureGaugeModuleScreen::createGUI);
TubeModuleClientRegistry.registerTubeModuleGUI(Names.MODULE_REDSTONE, RedstoneModuleScreen::new);
TubeModuleClientRegistry.registerTubeModuleGUI(Names.MODULE_LOGISTICS, LogisticsModuleScreen::new);
TubeModuleClientRegistry.registerTubeModuleGUI(Names.MODULE_THERMOSTAT, ThermostatModuleScreen::createGUI);

TubeModuleClientRegistry.registerTubeModuleRenderer(Names.MODULE_AIR_GRATE, AirGrateRenderer::new);
TubeModuleClientRegistry.registerTubeModuleRenderer(Names.MODULE_REDSTONE, RedstoneRenderer::new);
Expand All @@ -426,6 +429,7 @@ private static void registerTubeModuleFactories() {
TubeModuleClientRegistry.registerTubeModuleRenderer(Names.MODULE_FLOW_DETECTOR, FlowDetectorRenderer::new);
TubeModuleClientRegistry.registerTubeModuleRenderer(Names.MODULE_LOGISTICS, LogisticsRenderer::new);
TubeModuleClientRegistry.registerTubeModuleRenderer(Names.MODULE_VACUUM, VacuumRenderer::new);
TubeModuleClientRegistry.registerTubeModuleRenderer(Names.MODULE_THERMOSTAT, ThermostatRenderer::new);
}

private static void registerArmorClientUpgradeHandlers() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* This file is part of pnc-repressurized.
*
* pnc-repressurized is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* pnc-repressurized is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with pnc-repressurized. If not, see <https://www.gnu.org/licenses/>.
*/

package me.desht.pneumaticcraft.client.gui.tubemodule;

import me.desht.pneumaticcraft.client.gui.widget.WidgetCheckBox;
import me.desht.pneumaticcraft.client.gui.widget.WidgetColorSelector;
import me.desht.pneumaticcraft.client.gui.widget.WidgetLabel;
import me.desht.pneumaticcraft.client.gui.widget.WidgetTextField;
import me.desht.pneumaticcraft.client.gui.widget.WidgetTextFieldNumber;
import me.desht.pneumaticcraft.common.network.NetworkHandler;
import me.desht.pneumaticcraft.common.network.PacketSyncThermostatModuleToServer;
import me.desht.pneumaticcraft.common.network.PacketUpdatePressureModule;
import me.desht.pneumaticcraft.common.network.PacketTubeModuleColor;
import me.desht.pneumaticcraft.common.tubemodules.AbstractTubeModule;
import me.desht.pneumaticcraft.common.tubemodules.ThermostatModule;
import me.desht.pneumaticcraft.lib.Textures;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;

import static me.desht.pneumaticcraft.common.util.PneumaticCraftUtils.xlate;

public class SimpleThermostatModuleScreen extends AbstractTubeModuleScreen<ThermostatModule> {
private int color;
private int threshold;
private WidgetTextFieldNumber thresholdField;

public SimpleThermostatModuleScreen(ThermostatModule module) {
super(module);

ySize = 57;
}

@Override
public void init() {
super.init();

color = module.getColorChannel();
threshold = module.getThreshold();

addLabel(getTitle(), guiLeft + xSize / 2, guiTop + 5, WidgetLabel.Alignment.CENTRE);

int x = guiLeft + 10;
int y = guiTop + 24;
WidgetLabel colorLabel;
addRenderableWidget(colorLabel = new WidgetLabel(x, y, xlate("pneumaticcraft.gui.tubeModule.channel")));

x = guiLeft + 10 + colorLabel.getWidth() + 10;
WidgetColorSelector colorSelector = new WidgetColorSelector(x, y-4, w -> color = w.getColor().getId())
.withInitialColor(DyeColor.byId(color));
addRenderableWidget(colorSelector);

if (module.isUpgraded()) {
x = guiLeft + 10 + colorLabel.getWidth() + 10 + colorSelector.getWidth() + 10;
WidgetCheckBox advancedMode = new WidgetCheckBox(x, y, 0xFF404040, Component.literal("Advanced"), b -> {
module.advancedConfig = b.checked;
NetworkHandler.sendToServer(new PacketUpdatePressureModule(module));
}).setChecked(false);
advancedMode.setTooltip(Tooltip.create(xlate("pneumaticcraft.gui.tubeModule.advancedConfig.tooltip")));
addRenderableWidget(advancedMode);
}

x = guiLeft + 10;
y = guiTop + 22 + colorLabel.getHeight() + 10;
WidgetLabel thresholdLabel;
addRenderableWidget(thresholdLabel = new WidgetLabel(x, y, xlate("pneumaticcraft.gui.tubeModule.simpleConfig.threshold")));

x = guiLeft + 10 + thresholdLabel.getWidth() + 5;
thresholdField = new WidgetTextFieldNumber(font, x, y-1, 30, font.lineHeight + 2).setDecimals(0);
addRenderableWidget(thresholdField);
thresholdField.setWidth(40);
setInitialFocus(thresholdField);
thresholdField.setValue(threshold);

x = guiLeft + 10 + thresholdLabel.getWidth() + thresholdField.getWidth() + 10;
addRenderableWidget(new WidgetLabel(x, y, xlate("pneumaticcraft.gui.tubeModule.celsius")));
}

@Override
public void tick() {
super.tick();
if (module.advancedConfig) {
minecraft.setScreen(new ThermostatModuleScreen(module));
}
}

@Override
protected ResourceLocation getTexture() {
return Textures.GUI_MODULE_SIMPLE;
}

@Override
public void removed() {
super.removed();

module.setColorChannel(color);
module.setThreshold(thresholdField.getIntValue());
NetworkHandler.sendToServer(new PacketSyncThermostatModuleToServer(module));
}
}
Loading

0 comments on commit b5713e1

Please sign in to comment.