From 1e1de3cf124fa9eccf2e1f7cb859af383bc3e801 Mon Sep 17 00:00:00 2001 From: Bilka Date: Sat, 12 Mar 2022 20:40:02 +0100 Subject: [PATCH] Factorio 1.1: Added linked belt --- .../com/demod/fbsr/EntityRendererFactory.java | 2 ++ .../fbsr/entity/LinkedBeltRendering.java | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 FactorioBlueprintStringRenderer/src/com/demod/fbsr/entity/LinkedBeltRendering.java diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/EntityRendererFactory.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/EntityRendererFactory.java index dfb8bf5..06288e1 100644 --- a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/EntityRendererFactory.java +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/EntityRendererFactory.java @@ -57,6 +57,7 @@ import com.demod.fbsr.entity.InserterRendering; import com.demod.fbsr.entity.LabRendering; import com.demod.fbsr.entity.LampRendering; import com.demod.fbsr.entity.LandMineRendering; +import com.demod.fbsr.entity.LinkedBeltRendering; import com.demod.fbsr.entity.LinkedContainerRendering; import com.demod.fbsr.entity.LoaderRendering; import com.demod.fbsr.entity.LogisticContainerRendering; @@ -188,6 +189,7 @@ public class EntityRendererFactory { byType.put("loader-1x1", new LoaderRendering()); byType.put("locomotive", new RollingStockRendering()); byType.put("logistic-container", new LogisticContainerRendering()); + byType.put("linked-belt", new LinkedBeltRendering()); byType.put("linked-container", new LinkedContainerRendering()); byType.put("mining-drill", new MiningDrillRendering()); byType.put("offshore-pump", new OffshorePumpRendering()); diff --git a/FactorioBlueprintStringRenderer/src/com/demod/fbsr/entity/LinkedBeltRendering.java b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/entity/LinkedBeltRendering.java new file mode 100644 index 0000000..172fbe3 --- /dev/null +++ b/FactorioBlueprintStringRenderer/src/com/demod/fbsr/entity/LinkedBeltRendering.java @@ -0,0 +1,33 @@ +package com.demod.fbsr.entity; + +import java.util.function.Consumer; + +import com.demod.factorio.DataTable; +import com.demod.factorio.prototype.EntityPrototype; +import com.demod.fbsr.BlueprintEntity; +import com.demod.fbsr.Direction; +import com.demod.fbsr.EntityRendererFactory; +import com.demod.fbsr.RenderUtils; +import com.demod.fbsr.Renderer; +import com.demod.fbsr.Renderer.Layer; +import com.demod.fbsr.Sprite; +import com.demod.fbsr.WorldMap; +import com.demod.fbsr.WorldMap.BeltBend; + +public class LinkedBeltRendering extends EntityRendererFactory { + @Override + public void createRenderers(Consumer register, WorldMap map, DataTable dataTable, BlueprintEntity entity, + EntityPrototype prototype) { + boolean input = entity.json().getString("type").equals("input"); + Direction structDir = input ? entity.getDirection() : entity.getDirection().back(); + + Sprite beltSprite = TransportBeltRendering.getBeltSprite(prototype, entity.getDirection(), BeltBend.NONE); + + Sprite sprite = RenderUtils.getSpriteFromAnimation( + prototype.lua().get("structure").get(input ? "direction_in" : "direction_out").get("sheet")); + sprite.source.x += sprite.source.width * (structDir.cardinal()); + + register.accept(RenderUtils.spriteRenderer(Layer.ENTITY, beltSprite, entity, prototype)); + register.accept(RenderUtils.spriteRenderer(Layer.ENTITY2, sprite, entity, prototype)); + } +}