Skip to content

Commit

Permalink
Crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
Infer4Y committed Aug 13, 2019
1 parent def4650 commit 51fa3a2
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/client/renderables/Background.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void tick() {

@Override
public void second() {
if (count >= 0.d) {
count = -180;
if (count >= -10.d) {
count = -170;
day = !day;
} else {
count+=360.00000000d/2400.000000000d;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/client/renderables/BlockRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import common.item.ItemBlock;
import common.registries.Blocks;
import common.registries.Items;
import common.world.World;
import utils.FileUtils;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -84,6 +85,8 @@ public void mousePressed(MouseEvent e) {
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount() - 1);
texture = Game.textures.getTexture4(block.getName());
}
} else {
block.onBlockRightClick(Game.world, null);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/common/block/Block.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package common.block;

import client.Game;
import client.renderables.EntityRenderer;
import common.world.World;

Expand All @@ -11,6 +12,8 @@ public Block(String name){
this.name = name;
}

public void onBlockRightClick(World world, EntityRenderer entity){ }

public void onBlockCollision(World world, EntityRenderer entity){ }

public void onTick(World world, int x, int y){ }
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/common/block/BlockCrafter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package common.block;

import client.Game;
import client.renderables.EntityRenderer;
import common.item.ItemBlock;
import common.registries.Blocks;
import common.registries.Items;
import common.world.World;

public class BlockCrafter extends Block {
public BlockCrafter(String name) {
super(name);
}

@Override
public void onBlockRightClick(World world, EntityRenderer entity) {
super.onBlockRightClick(world, entity);
if (Blocks.stone.getName().equals(Game.headsUpDisplay.getSelected().getItemStack().getItem().getName())){
for (int i = 0; i < Game.headsUpDisplay.getSlots().length; i++) {
if (Game.headsUpDisplay.getSlots()[i].getItemStack().getItem() instanceof ItemBlock) {
if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock() == Blocks.wood_producer) {
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(Game.headsUpDisplay.getSlots()[i].getItemStack().getAmount() + 1);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
} else if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock().isAir()){
Game.headsUpDisplay.getSlots()[i].getItemStack().setItem(Items.getItem(Blocks.wood_producer.getName()));
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(1);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
}
}
}
} else if (Blocks.log.getName().equals(Game.headsUpDisplay.getSelected().getItemStack().getItem().getName())){
for (int i = 0; i < Game.headsUpDisplay.getSlots().length; i++) {
if (Game.headsUpDisplay.getSlots()[i].getItemStack().getItem() instanceof ItemBlock) {
if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock() == Blocks.planks) {
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(Game.headsUpDisplay.getSlots()[i].getItemStack().getAmount() + 4);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
} else if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock().isAir()){
Game.headsUpDisplay.getSlots()[i].getItemStack().setItem(Items.getItem(Blocks.planks.getName()));
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(4);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
}
}
}
}
}

@Override
public void onTick(World world, int x, int y) {
super.onTick(world, x, y);
}

@Override
public boolean isSolid() {
return super.isSolid();
}
}
28 changes: 28 additions & 0 deletions src/main/java/common/block/BlockLog.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
package common.block;

import client.Game;
import client.renderables.EntityRenderer;
import common.item.ItemBlock;
import common.registries.Blocks;
import common.registries.Items;
import common.world.World;

public class BlockLog extends Block {
public BlockLog(String name) {
super(name);
}

@Override
public void onBlockRightClick(World world, EntityRenderer entity) {
super.onBlockRightClick(world, entity);
if (Blocks.stone.getName().equals(Game.headsUpDisplay.getSelected().getItemStack().getItem().getName())){
for (int i = 0; i < Game.headsUpDisplay.getSlots().length; i++) {
if (Game.headsUpDisplay.getSlots()[i].getItemStack().getItem() instanceof ItemBlock) {
if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock() == Blocks.crafter) {
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(Game.headsUpDisplay.getSlots()[i].getItemStack().getAmount() + 1);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
} else if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock().isAir()){
Game.headsUpDisplay.getSlots()[i].getItemStack().setItem(Items.getItem(Blocks.crafter.getName()));
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(1);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
}
}
}
}
}

@Override
public boolean isSolid() {
return false;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/common/block/BlockWoodProducer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package common.block;

import client.Game;
import client.renderables.EntityRenderer;
import common.item.ItemBlock;
import common.registries.Blocks;
import common.registries.Items;
import common.world.World;

public class BlockWoodProducer extends Block {
public BlockWoodProducer(String name) {
super(name);
}

@Override
public void onBlockRightClick(World world, EntityRenderer entity) {
super.onBlockRightClick(world, entity);
if (Blocks.sapling.getName().equals(Game.headsUpDisplay.getSelected().getItemStack().getItem().getName())&& Game.headsUpDisplay.getSelected().getItemStack().getAmount() >= 1){
for (int i = 0; i < Game.headsUpDisplay.getSlots().length; i++) {
if (Game.headsUpDisplay.getSlots()[i].getItemStack().getItem() instanceof ItemBlock) {
if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock() == Blocks.log) {
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(Game.headsUpDisplay.getSlots()[i].getItemStack().getAmount() + 4);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
} else if (((ItemBlock) Game.headsUpDisplay.getSlots()[i].getItemStack().getItem()).getBlock().isAir()){
Game.headsUpDisplay.getSlots()[i].getItemStack().setItem(Items.getItem(Blocks.log.getName()));
Game.headsUpDisplay.getSlots()[i].getItemStack().setAmount(4);
Game.headsUpDisplay.getSelected().getItemStack().setAmount(Game.headsUpDisplay.getSelected().getItemStack().getAmount()-1);
break;
}
}
}
}
}

@Override
public void onTick(World world, int x, int y) {
super.onTick(world, x, y);
}

@Override
public boolean isSolid() {
return false;
}
}
4 changes: 3 additions & 1 deletion src/main/java/common/registries/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public class Blocks {
public static BlockLeaf leaf = new BlockLeaf("leaves");
public static Block planks = new Block("planks");
public static Block sapling = new BlockSapling("sapling");
public static BlockWoodProducer wood_producer = new BlockWoodProducer("wood_producer");
public static BlockCrafter crafter = new BlockCrafter("crafter");

public static void init(){
register(grass, dirt, stone, air, launcher, log, leaf, planks, sapling);
register(grass, dirt, stone, air, launcher, log, leaf, planks, sapling, wood_producer, crafter);
}

private static void register(Block block){
Expand Down
Binary file added src/main/resources/tex/blocks/crafter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/tex/blocks/wood_producer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 51fa3a2

Please sign in to comment.