Skip to content

Commit

Permalink
Finished Bed!
Browse files Browse the repository at this point in the history
  • Loading branch information
Quarris committed Mar 22, 2021
1 parent 76d5d25 commit 49abbea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
44 changes: 22 additions & 22 deletions src/main/java/de/ellpeck/rockbottom/world/tile/BedTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 49abbea

Please sign in to comment.