Skip to content

Commit

Permalink
materials rework step 1: reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 1, 2019
1 parent 6bf0d82 commit 0bb8b5c
Show file tree
Hide file tree
Showing 46 changed files with 709 additions and 649 deletions.
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.nms.interfaces;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.util.BoundingBox;
import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag;
import net.aufdemrand.denizencore.utilities.debugging.dB;
Expand Down Expand Up @@ -476,4 +477,8 @@ else if (337.5 <= yaw && yaw < 360.0) {
public abstract boolean isCarryingChest(Entity horse);

public abstract void setCarryingChest(Entity horse, boolean carrying);

public BlockData getBlockDataFor(FallingBlock entity) {
return NMSHandler.getInstance().getBlockHelper().getBlockData(entity.getMaterial(), (byte) 0);
}
}
5 changes: 3 additions & 2 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -38,6 +38,7 @@
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.core.*;
import net.aufdemrand.denizen.utilities.*;
import net.aufdemrand.denizen.utilities.blocks.OldMaterialsHelper;
import net.aufdemrand.denizen.utilities.command.CommandManager;
import net.aufdemrand.denizen.utilities.command.Injector;
import net.aufdemrand.denizen.utilities.command.messaging.Messaging;
Expand Down Expand Up @@ -772,8 +773,8 @@ public void onEnable() {
}

try {
// Initialize non-standard dMaterials
dMaterial._initialize();
// Initialize old Materials helper
OldMaterialsHelper._initialize();

// register properties that add Bukkit code to core objects
PropertyParser.registerProperty(BukkitScriptProperties.class, dScript.class);
Expand Down
Expand Up @@ -113,8 +113,8 @@ else if (name.equals("old_material")) {
@EventHandler
public void onBlockBuilt(BlockCanBuildEvent event) {
location = new dLocation(event.getBlock().getLocation());
old_material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
new_material = dMaterial.getMaterialFrom(event.getMaterial()); // Deprecated because it doesn't have proper data
old_material = new dMaterial(event.getBlock());
new_material = new dMaterial(event.getMaterial()); // Deprecated because it doesn't have proper data
cancelled = !event.isBuildable();
this.event = event;
fire();
Expand Down
Expand Up @@ -95,7 +95,7 @@ else if (name.equals("material")) {
@EventHandler
public void onBlockBurns(BlockBurnEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -133,7 +133,7 @@ else if (name.equals("velocity")) {
@EventHandler
public void onBlockDispenses(BlockDispenseEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
item = new dItem(event.getItem());
cancelled = event.isCancelled();
velocity = new dLocation(null, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
Expand Down
Expand Up @@ -93,7 +93,7 @@ else if (name.equals("material")) {
@EventHandler
public void onBlockFades(BlockFadeEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -97,7 +97,7 @@ else if (name.equals("entity")) {
public void onBlockFalls(EntityChangeBlockEvent event) {
entity = new dEntity(event.getEntity());
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -94,7 +94,7 @@ else if (name.equals("material")) {
public void onBlockForms(BlockFormEvent event) {

location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getNewState().getType(), event.getNewState().getData().getData());
material = new dMaterial(event.getNewState());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -97,7 +97,7 @@ else if (name.equals("material")) {
@EventHandler
public void onBlockGrows(BlockGrowEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getNewState().getType(), event.getNewState().getData().getData());
material = new dMaterial(event.getNewState());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -110,7 +110,7 @@ else if (name.equals("cause")) {
@EventHandler
public void onBlockIgnites(BlockIgniteEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
entity = null;
if (event.getIgnitingEntity() != null) {
entity = new dEntity(event.getIgnitingEntity());
Expand Down
Expand Up @@ -106,8 +106,8 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
return;
}
location = new dLocation(event.getBlock().getLocation());
new_material = dMaterial.getMaterialFrom(changedType);
material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
new_material = new dMaterial(changedType);
material = new dMaterial(location.getBlock());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -101,7 +101,7 @@ else if (name.equals("source_location")) {
public void onBlockSpreads(BlockSpreadEvent event) {
source = new dLocation(event.getBlock().getLocation());
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getSource().getType(), event.getSource().getData());
material = new dMaterial(event.getSource());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -150,8 +150,8 @@ else if (name.equals("old_material")) {
public void onEntityChangesBlock(EntityChangeBlockEvent event) {
entity = new dEntity(event.getEntity());
location = new dLocation(event.getBlock().getLocation());
old_material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
new_material = dMaterial.getMaterialFrom(event.getTo());
old_material = new dMaterial(location.getBlock());
new_material = new dMaterial(event.getTo());
cuboids = null;
cancelled = event.isCancelled();
this.event = event;
Expand Down
Expand Up @@ -117,7 +117,7 @@ else if (name.equals("entity")) {
@EventHandler
public void onEntityFormsBlock(EntityBlockFormEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
entity = new dEntity(event.getEntity());
cancelled = event.isCancelled();
this.event = event;
Expand Down
Expand Up @@ -125,7 +125,7 @@ else if (name.equals("cuboids")) { // NOTE: Deprecated in favor of context.locat
public void onEntityInteract(EntityInteractEvent event) {
entity = new dEntity(event.getEntity());
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
cuboids = null;
cancelled = event.isCancelled();
this.event = event;
Expand Down
Expand Up @@ -180,7 +180,7 @@ public void onProjectileHits(ProjectileHitEvent event) {
if (block == null) {
return;
}
material = dMaterial.getMaterialFrom(block.getType(), block.getData());
material = new dMaterial(block);
shooter = projectile.getShooter();
location = new dLocation(block.getLocation());
this.event = event;
Expand Down
Expand Up @@ -105,7 +105,7 @@ else if (name.equals("location")) {
public void onVehicleCollidesBlock(VehicleBlockCollisionEvent event) {
vehicle = new dEntity(event.getVehicle());
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
this.event = event;
fire();
}
Expand Down
Expand Up @@ -160,7 +160,7 @@ public void onPlayerBreaksBlock(BlockBreakEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
location = new dLocation(event.getBlock().getLocation());
cuboids = null;
cancelled = event.isCancelled();
Expand Down
Expand Up @@ -149,7 +149,7 @@ public void onPlayerChangesSign(SignChangeEvent event) {
return;
}
Sign sign = (Sign) state;
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
location = new dLocation(event.getBlock().getLocation());
cuboids = null;
old_sign = new dList(Arrays.asList(sign.getLines()));
Expand Down
Expand Up @@ -156,7 +156,7 @@ public boolean matches(ScriptPath path) {
return false;
}

dMaterial material = event.hasBlock() ? dMaterial.getMaterialFrom(event.getClickedBlock().getType(), event.getClickedBlock().getData()) : null;
dMaterial material = event.hasBlock() ? new dMaterial(event.getClickedBlock()) : null;
String mat = CoreUtilities.getXthArg(index, lower);
if (mat.length() > 0
&& !withHelpList.contains(mat)
Expand Down
Expand Up @@ -127,7 +127,7 @@ public void onPlayerDamagesBlock(BlockDamageEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
location = new dLocation(event.getBlock().getLocation());
cuboids = null;
cancelled = event.isCancelled();
Expand Down
Expand Up @@ -111,7 +111,7 @@ public void onBucketFill(PlayerBucketFillEvent event) {
entity = new dEntity(event.getPlayer());
location = new dLocation(event.getBlockClicked().getLocation());
item = new dItem(event.getItemStack());
material = dMaterial.getMaterialFrom(event.getBlockClicked().getType(), event.getBlockClicked().getData());
material = new dMaterial(event.getBlockClicked());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -106,8 +106,7 @@ else if (name.equals("material")) {
return material;
}
else if (name.equals("old_material")) {
MaterialData materialData = event.getBlockReplacedState().getData();
return dMaterial.getMaterialFrom(materialData.getItemType(), materialData.getData());
return new dMaterial(event.getBlockReplacedState().getData());
}
else if (name.equals("item_in_hand")) {
return item_in_hand;
Expand All @@ -127,7 +126,7 @@ public void onPlayerPlacesBlock(BlockPlaceEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
location = new dLocation(event.getBlock().getLocation());
cancelled = event.isCancelled();
item_in_hand = new dItem(event.getItemInHand());
Expand Down
Expand Up @@ -109,7 +109,7 @@ public void playerStandsOn(PlayerInteractEvent event) {
if (event.getAction() != Action.PHYSICAL) {
return;
}
material = dMaterial.getMaterialFrom(event.getClickedBlock().getType(), event.getClickedBlock().getData());
material = new dMaterial(event.getClickedBlock());
location = new dLocation(event.getClickedBlock().getLocation());
cancelled = event.isCancelled();
this.event = event;
Expand Down
Expand Up @@ -126,7 +126,7 @@ public void onPlayerStatisticIncrements(PlayerStatisticIncrementEvent event) {
previous_value = null;
statistic = event.getStatistic();
if (statistic.getType() == Statistic.Type.BLOCK || statistic.getType() == Statistic.Type.ITEM) {
material = dMaterial.getMaterialFrom(event.getMaterial());
material = new dMaterial(event.getMaterial());
}
else if (statistic.getType() == Statistic.Type.ENTITY) {
entity = new dEntity(DenizenEntityType.getByName(event.getEntityType().name()));
Expand Down
Expand Up @@ -60,7 +60,7 @@ public boolean matches(ScriptPath path) {
String lower = path.eventLower;

String mat = CoreUtilities.getXthArg(3, lower);
dMaterial material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
dMaterial material = new dMaterial(location.getBlock());
if (!tryMaterial(material, mat)) {
return false;
}
Expand Down
Expand Up @@ -105,7 +105,7 @@ public void onPlayerTakesFromFurnace(FurnaceExtractEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
item = new dItem(dMaterial.getMaterialFrom(event.getItemType()), event.getItemAmount());
item = new dItem(event.getItemType(), event.getItemAmount());
location = new dLocation(event.getBlock().getLocation());
xp = event.getExpToDrop();
this.event = event;
Expand Down
Expand Up @@ -89,7 +89,7 @@ else if (name.equals("material")) {
@EventHandler
public void onLeafDecays(LeavesDecayEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -97,7 +97,7 @@ else if (name.equals("material")) {
public void onLiquidSpreads(BlockFromToEvent event) {
destination = new dLocation(event.getToBlock().getLocation());
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Expand Up @@ -113,7 +113,7 @@ else if (name.equals("length")) {
@EventHandler
public void onPistonExtends(BlockPistonExtendEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
sticky = new Element(event.isSticky() ? "true" : "false");
relative = new dLocation(event.getBlock().getRelative(event.getDirection()).getLocation());
blocks = new dList();
Expand Down
Expand Up @@ -115,7 +115,7 @@ else if (name.equals("retract_location")) {
@EventHandler
public void onPistonRetracts(BlockPistonRetractEvent event) {
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
material = new dMaterial(event.getBlock());
sticky = new Element(event.isSticky() ? "true" : "false");
relative = new dLocation(event.getBlock().getRelative(event.getDirection().getOppositeFace()).getLocation());
blocks = new dList();
Expand Down
Expand Up @@ -130,7 +130,7 @@ public void onStructureGrow(StructureGrowEvent event) {
new_materials = new dList();
for (BlockState block : event.getBlocks()) {
blocks.add(new dLocation(block.getLocation()).identify());
new_materials.add(dMaterial.getMaterialFrom(block.getType(), block.getRawData()).identify());
new_materials.add(new dMaterial(block.getType(), block.getRawData()).identify());
}
this.event = event;
cancelled = event.isCancelled();
Expand Down
Expand Up @@ -6,6 +6,7 @@
import net.aufdemrand.denizen.nms.interfaces.BlockHelper;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.utilities.Utilities;
import net.aufdemrand.denizen.utilities.blocks.OldMaterialsHelper;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizencore.objects.*;
Expand Down Expand Up @@ -433,7 +434,7 @@ private boolean matchesMaterialList(Location loc, List<dMaterial> materials) {
if (materials == null) {
return true;
}
dMaterial mat = dMaterial.getMaterialFrom(loc.getBlock().getType(), loc.getBlock().getData());
dMaterial mat = OldMaterialsHelper.getMaterialFrom(loc.getBlock().getType(), loc.getBlock().getData());
for (dMaterial material : materials) {
if (mat.equals(material) || (mat.getMaterial() == material.getMaterial()
&& (material.getData() == null || material.getData() == 0))) { // TODO: only if null?
Expand Down Expand Up @@ -470,7 +471,7 @@ public List<dLocation> getBlocks_internal(List<dMaterial> materials) {
for (int z = 0; z != z_distance + 1; z++) {
loc = new dLocation(loc_1.clone().add(x, y, z));
if (loc.getY() < 0 || loc.getY() > 255) {
continue; // TODO: Why is this ever possible?
continue;
}
if (!filter.isEmpty()) { // TODO: Should 'filter' exist?
// Check filter
Expand Down
Expand Up @@ -1856,7 +1856,7 @@ else if (mtr.angle == BlockFace.EAST) {
// Returns the material of a fallingblock-type entity.
// -->
if (attribute.startsWith("fallingblock_material") && entity instanceof FallingBlock) {
return dMaterial.getMaterialFrom(((FallingBlock) entity).getMaterial())
return new dMaterial(NMSHandler.getInstance().getEntityHelper().getBlockDataFor((FallingBlock) entity))
.getAttribute(attribute.fulfill(1));
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
import net.aufdemrand.denizen.scripts.containers.core.ItemScriptHelper;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.utilities.MaterialCompat;
import net.aufdemrand.denizen.utilities.blocks.OldMaterialsHelper;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.objects.notable.Notable;
Expand Down Expand Up @@ -500,9 +501,9 @@ public void setItemScript(ItemScriptContainer script) {

public dMaterial getMaterial() {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) {
return dMaterial.getMaterialFrom(getItemStack().getType());
return new dMaterial(getItemStack().getType());
}
return dMaterial.getMaterialFrom(getItemStack().getType(), getItemStack().getData().getData());
return OldMaterialsHelper.getMaterialFrom(getItemStack().getType(), getItemStack().getData().getData());
}

public String getMaterialName() {
Expand Down

0 comments on commit 0bb8b5c

Please sign in to comment.