Skip to content

Commit

Permalink
Consider Multi-block Blocks as a Single Unit (#61)
Browse files Browse the repository at this point in the history
block: Implement Multiblocks for better block handling

* Implement CreeperMultiblock for some blocks

* Fixed double chests/other containers
  * Shulkers will eventually need to be revisited - drop should drop full shulker, not contents separately.
* Reduced redundant explosion replacement entries for "dependent" multiblocks
  • Loading branch information
Jikoo authored and nitnelave committed Nov 1, 2018
1 parent 54430c3 commit 589377e
Show file tree
Hide file tree
Showing 22 changed files with 307 additions and 452 deletions.
Binary file removed lib/PlayerHeads.jar
Binary file not shown.
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
<packaging>jar</packaging>
<url>https://github.com/nitnelave/CreeperHeal</url>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -171,12 +177,5 @@
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
13 changes: 1 addition & 12 deletions src/main/java/com/nitnelave/CreeperHeal/PluginHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class PluginHandler
private static MobArenaHandler maHandler = null;
private static LWC lwc = null;

private static final boolean spout;

static
{
Plugin lwcp = detectPlugin("LWC");
Expand All @@ -32,7 +30,6 @@ public class PluginHandler
if (detectPlugin("MobArena") != null)
maHandler = new MobArenaHandler();

spout = detectPlugin("Spout") != null;
}

/*
Expand Down Expand Up @@ -68,10 +65,7 @@ public static boolean isProtected(Block block)
*/
public static boolean isInArena(Location location)
{
if (maHandler != null)
if (maHandler.inRegion(location))
return true; //Explosion inside a mob arena
return false;
return maHandler != null && maHandler.inRegion(location);
}

/**
Expand All @@ -84,9 +78,4 @@ public static boolean isFactionsEnabled()
return detectPlugin("Factions") != null;
}

public static boolean isSpoutEnabled()
{
return spout;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CreeperBed extends CreeperBlock
*/
CreeperBed(BlockState blockState)
{
super(blockState);
Bed bedData = castData(blockState, Bed.class);
orientation = bedData.getFacing();
Block block = blockState.getBlock();
Expand Down
37 changes: 14 additions & 23 deletions src/main/java/com/nitnelave/CreeperHeal/block/CreeperBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.nitnelave.CreeperHeal.config.CfgVal;
import com.nitnelave.CreeperHeal.config.CreeperConfig;
import com.nitnelave.CreeperHeal.utils.CreeperLog;
import com.nitnelave.CreeperHeal.utils.CreeperUtils;
import com.nitnelave.CreeperHeal.utils.ShortLocation;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -85,18 +85,16 @@ public class CreeperBlock implements Replaceable
public static CreeperBlock newBlock(BlockState state)
{
CreeperConfig.getWorld(state.getWorld()).getReplacement(state);
//if (PluginHandler.isSpoutEnabled () && SpoutBlock.isCustomBlock (blockState))
// return new SpoutBlock (blockState);
if (state instanceof InventoryHolder)
return new CreeperChest(state);
return new CreeperContainer(state);
if (state.getType().hasGravity())
return new CreeperPhysicsBlock(state);
switch (state.getType())
{
case BED_BLOCK:
return new CreeperBed(state);
case DOUBLE_PLANT:
return new CreeperFlower(state);
return new CreeperFlower(state);
case RAILS:
case POWERED_RAIL:
case DETECTOR_RAIL:
Expand Down Expand Up @@ -156,14 +154,11 @@ protected CreeperBlock(BlockState blockState)
this.blockState = blockState;
}

protected CreeperBlock()
{}

/*
* Get whether the block is empty, i.e. if a player can breathe inside it
* and if it can be replaced by other blocks (snow, water...)
*/
private static boolean isEmpty(Material type)
protected static boolean isEmpty(Material type)
{
return EMPTY_BLOCKS.contains(type);
}
Expand Down Expand Up @@ -243,7 +238,6 @@ public static boolean isDependent(Material type)
*/
public void update()
{
getLocation().getChunk().load();
blockState.update(true, false);
getWorld().playSound(getLocation(), CreeperConfig.getSound(), CreeperConfig.getInt(CfgVal.SOUND_VOLUME) / 10F, random.nextFloat() * 2);
}
Expand All @@ -259,16 +253,6 @@ public Material getType()
return blockState.getType();
}

/**
* Get the block's raw data.
*
* @return The block's raw data.
*/
public byte getRawData()
{
return blockState.getRawData();
}

/**
* Drop the corresponding items on the ground.
*
Expand Down Expand Up @@ -302,7 +286,7 @@ public boolean drop(boolean forced)
@Override
public final boolean replace(boolean shouldDrop)
{
if (checkForDrop(getBlock()))
if (checkForDrop())
return true;

if (!shouldDrop && isDependent(getType())
Expand All @@ -327,8 +311,10 @@ public static boolean isSolid(Block block)
return block.getType().isSolid();
}

protected boolean checkForDrop(Block block)
protected boolean checkForDrop()
{

Block block = blockState.getBlock();
Material type = block.getType();

if (!CreeperConfig.getBool(CfgVal.OVERWRITE_BLOCKS) && !isEmpty(type))
Expand All @@ -341,7 +327,7 @@ protected boolean checkForDrop(Block block)
{
CreeperBlock b = CreeperBlock.newBlock(block.getState());
if (b == null)
throw new IllegalArgumentException("Null block for: " + block.getState().getType().toString());
throw new IllegalArgumentException("Null block for: " + block.getType().toString());
b.drop(true);
b.remove();
}
Expand Down Expand Up @@ -427,6 +413,11 @@ public List<NeighborBlock> getDependentNeighbors()
return neighbors;
}

void record(Collection<ShortLocation> checked)
{
checked.add(new ShortLocation(getLocation()));
}

protected <T extends MaterialData> T castData(BlockState b, Class<T> c)
{
MaterialData data = b.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
class CreeperBrick extends CreeperBlock
{

protected CreeperBrick(BlockState blockState)
CreeperBrick(BlockState blockState)
{
super(blockState);

if (CreeperConfig.getBool(CfgVal.CRACK_DESTROYED_BRICKS) && getRawData() == (byte) 0)
if (CreeperConfig.getBool(CfgVal.CRACK_DESTROYED_BRICKS) && blockState.getRawData() == (byte) 0)
blockState.setRawData((byte) 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ protected CreeperButton(BlockState b)
{
super(b);

b.setRawData((byte) (getRawData() & 7));
b.setRawData((byte) (b.getRawData() & 7));
}
}
Loading

0 comments on commit 589377e

Please sign in to comment.