diff --git a/src/main/java/de/ellpeck/rockbottom/render/tile/BedTileRenderer.java b/src/main/java/de/ellpeck/rockbottom/render/tile/BedTileRenderer.java index 97a3a8e6..95bd6db7 100644 --- a/src/main/java/de/ellpeck/rockbottom/render/tile/BedTileRenderer.java +++ b/src/main/java/de/ellpeck/rockbottom/render/tile/BedTileRenderer.java @@ -6,12 +6,12 @@ import de.ellpeck.rockbottom.api.assets.IAssetManager; import de.ellpeck.rockbottom.api.render.tile.MultiTileRenderer; import de.ellpeck.rockbottom.api.tile.state.TileState; -import de.ellpeck.rockbottom.api.util.Colors; import de.ellpeck.rockbottom.api.util.Pos2; import de.ellpeck.rockbottom.api.util.reg.ResourceName; import de.ellpeck.rockbottom.api.world.IWorld; import de.ellpeck.rockbottom.api.world.layer.TileLayer; import de.ellpeck.rockbottom.world.tile.BedTile; +import de.ellpeck.rockbottom.world.tile.entity.BedTileEntity; import java.util.HashMap; import java.util.Map; @@ -42,14 +42,19 @@ public void render(IGameInstance game, IAssetManager manager, IRenderer renderer // Draw Frame super.render(game, manager, renderer, world, tile, state, x, y, layer, renderX, renderY, scale, light); - // Draw Cover - Pos2 innerCoord = tile.getInnerCoord(state); - manager.getTexture(this.coverTextures.get(innerCoord)).getPositionalVariation(x, y).draw(renderX, renderY, scale, scale, light, state.get(StaticTileProps.COVER_COLOR).color); + Pos2 mainPos = tile.getMainPos(x, y, state); + BedTileEntity bedTE = world.getTileEntity(mainPos.getX(), mainPos.getY(), BedTileEntity.class); - // Draw Pillow - boolean isFacingRight = state.get(StaticTileProps.FACING_RIGHT); - if (tile.isPillowPos(world, x, y)) { - manager.getTexture(isFacingRight ? this.rightPillow : this.leftPillow).draw(renderX, renderY, scale, scale, light, state.get(StaticTileProps.PILLOW_COLOR).color); + if (bedTE != null) { + // Draw Cover + Pos2 innerCoord = tile.getInnerCoord(state); + manager.getTexture(this.coverTextures.get(innerCoord)).getPositionalVariation(x, y).draw(renderX, renderY, scale, scale, light, bedTE.coverColor.color); + + // Draw Pillow + boolean isFacingRight = state.get(StaticTileProps.FACING_RIGHT); + if (tile.isPillowPos(world, x, y)) { + manager.getTexture(isFacingRight ? this.rightPillow : this.leftPillow).draw(renderX, renderY, scale, scale, light, bedTE.pillowColor.color); + } } } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/rockbottom/world/tile/BedTile.java b/src/main/java/de/ellpeck/rockbottom/world/tile/BedTile.java index e73f73ba..48e4e574 100644 --- a/src/main/java/de/ellpeck/rockbottom/world/tile/BedTile.java +++ b/src/main/java/de/ellpeck/rockbottom/world/tile/BedTile.java @@ -28,8 +28,6 @@ public class BedTile extends MultiTile { public BedTile() { super(ResourceName.intern("bed")); this.addProps(StaticTileProps.FACING_RIGHT); - this.addProps(StaticTileProps.PILLOW_COLOR); - this.addProps(StaticTileProps.COVER_COLOR); } @Override @@ -38,36 +36,38 @@ public boolean onInteractWith(IWorld world, int x, int y, TileLayer layer, doubl double hitY = mouseY - y; TileState thisState = world.getState(x, y); - boolean isMainPos = this.isMainPos(x, y, thisState); boolean isFacingRight = thisState.get(StaticTileProps.FACING_RIGHT); ItemInstance held = player.getSelectedItem(); if (held != null && held.getItem() == GameContent.Tiles.FLOWER.getItem()) { - DyeColor flowerColor = DyeColor.fromMeta(held.getMeta()); - int otherX = isMainPos ? x + 1 : x - 1; - TileState otherState = world.getState(otherX, y); + Pos2 mainPos = this.getMainPos(x, y, thisState); + BedTileEntity bedTE = world.getTileEntity(mainPos.getX(), mainPos.getY(), BedTileEntity.class); + boolean used = false; - if (this.isPillowPos(world, x, y)) { - if (hitY > 4/12f && hitY < 8/12f) { - if (isFacingRight && hitX > 0.5f || !isFacingRight && hitX < 0.5f) { - world.setState(x, y, thisState.prop(StaticTileProps.PILLOW_COLOR, flowerColor)); - world.setState(otherX, y, otherState.prop(StaticTileProps.PILLOW_COLOR, flowerColor)); - used = true; + if (bedTE != null) { + DyeColor flowerColor = DyeColor.fromMeta(held.getMeta()); + if (this.isPillowPos(world, x, y)) { + // Check if clicked on pillow + if (hitY > 4/12f && hitY < 8/12f) { + if (isFacingRight && hitX > 0.5f || !isFacingRight && hitX < 0.5f) { + bedTE.pillowColor = flowerColor; + used = true; + } } } - } - if (!used) { - if (hitY < 0.5) { - world.setState(x, y, thisState.prop(StaticTileProps.COVER_COLOR, flowerColor)); - world.setState(otherX, y, otherState.prop(StaticTileProps.COVER_COLOR, flowerColor)); - used = true; + if (!used) { + // Check if clicked on cover (bottom half of tile) + if (hitY < 0.5) { + bedTE.coverColor = flowerColor; + used = true; + } } - } - if (used) { - player.getInv().set(player.getSelectedSlot(), held.removeAmount(1).nullIfEmpty()); - return true; + if (used) { + player.getInv().set(player.getSelectedSlot(), held.removeAmount(1).nullIfEmpty()); + return true; + } } }