/
FirestarterLogic.java
92 lines (72 loc) · 2.91 KB
/
FirestarterLogic.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package slimeknights.tmechworks.blocks.logic;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import slimeknights.tmechworks.library.Util;
import javax.annotation.Nonnull;
import java.util.List;
public class FirestarterLogic extends RedstoneMachineLogicBase
{
private boolean shouldExtinguish = true;
public FirestarterLogic ()
{
super(Util.prefix("inventory.firestarter"), 0);
}
@Override public void onRedstoneUpdate()
{
super.onRedstoneUpdate();
setFire();
}
public void setFire ()
{
if(world.isRemote)
return;
EnumFacing facing = getFacingDirection();
BlockPos loc = getPos();
BlockPos position = new BlockPos(loc.getX() + facing.getXOffset(), loc.getY() + facing.getYOffset(), loc.getZ() + facing.getZOffset());
IBlockState state = world.getBlockState(position);
if (getRedstoneState() > 0)
{
if (state.getBlock() == Blocks.AIR && Blocks.FIRE.canPlaceBlockAt(world, position))
{
world.playSound(null, loc.getX() + 0.5D, loc.getY() + 0.5D, loc.getZ() + 0.5D, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, Util.rand.nextFloat() * 0.4F + 0.8F);
world.setBlockState(position, Blocks.FIRE.getDefaultState(), 11);
}
} else if (shouldExtinguish && (state.getBlock() == Blocks.FIRE || state.getBlock() == Blocks.PORTAL))
{
world.playSound(null, loc.getX() + 0.5D, loc.getY() + 0.5D, loc.getZ() + 0.5D, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1.0F, Util.rand.nextFloat() * 0.4F + 0.8F);
world.setBlockToAir(position);
}
}
public void setShouldExtinguish(boolean shouldExtinguish) {
this.shouldExtinguish = shouldExtinguish;
markDirty();
}
public boolean getShouldExtinguish() {
return shouldExtinguish;
}
@Override public NBTTagCompound writeToNBT (NBTTagCompound tags)
{
tags = super.writeToNBT(tags);
tags.setBoolean("ShouldExtinguish", shouldExtinguish);
return tags;
}
@Override public void readFromNBT (NBTTagCompound tags)
{
super.readFromNBT(tags);
shouldExtinguish = tags.getBoolean("ShouldExtinguish");
}
@Override
public void getInformation(@Nonnull List<String> info, InformationType type) {
super.getInformation(info, type);
if(type != InformationType.BODY) {
return;
}
info.add(I18n.format("tmechworks.hud.behaviour") + ": " + I18n.format("tmechworks.hud.behaviour.firestarter." + (getShouldExtinguish() ? "extinguish" : "keep")));
}
}