Skip to content

Commit

Permalink
Fix long distance remote not working
Browse files Browse the repository at this point in the history
  • Loading branch information
SCLeoX committed May 7, 2020
1 parent 4d042a5 commit f46f32c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void clientUse(ItemStack itemStack, EntityPlayer player) {
IntegratedNBT.getNetworkChannel().sendToServer(new NBTExtractorRemoteRequestMessage());
}

private NBTTagCompound getModNBT(ItemStack itemStack) {
public NBTTagCompound getModNBT(ItemStack itemStack) {
return itemStack.getOrCreateSubCompound(IntegratedNBT.MODID);
}

Expand Down
60 changes: 39 additions & 21 deletions src/main/java/me/tepis/integratednbt/NBTExtractorTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,33 @@ public boolean isUsableByPlayer(@Nonnull EntityPlayer player) {
if (this.world.getTileEntity(this.pos) != this) {
return false;
} else {
return player.getDistanceSq(
if (player.getDistanceSq(
(double) this.pos.getX() + 0.5D,
(double) this.pos.getY() + 0.5D,
(double) this.pos.getZ() + 0.5D
) <= 64.0D;
) <= 64.0D) {
return true;
}
return (this.isRemote(player.getHeldItemMainhand()) ||
this.isRemote(player.getHeldItemOffhand()));
}
}

/**
* Tests whether the given item stack is a remote for this NBT Extractor.
*/
private boolean isRemote(ItemStack itemStack) {
if (itemStack.getItem() != NBTExtractorRemote.getInstance()) {
return false;
}
NBTTagCompound tag = NBTExtractorRemote.getInstance().getModNBT(itemStack);
return (tag.hasKey("world")) &&
(tag.getInteger("world") == this.world.provider.getDimension()) &&
(tag.getInteger("x") == this.pos.getX()) &&
(tag.getInteger("y") == this.pos.getY()) &&
(tag.getInteger("z") == this.pos.getZ());
}

@Override
public void openInventory(@Nonnull EntityPlayer player) {

Expand Down Expand Up @@ -570,12 +589,29 @@ public NBTExtractedVariableFacade create(int id) {
}
}

@Nullable
private ItemStack getVariableByOperatorMode() {
return this.getVariableUsingValue(ValueOperator.of(new NBTExtractionOperator(
this.extractionPath,
this.defaultNBTId
)));
}

@Nullable
private ItemStack getVariableByValueMode() {
this.refreshVariables(true);
NBTBase extractedNBT = this.extractionPath.extract(this.lastEvaluatedNBT);
IValue value = extractedNBT == null
? NBTValueConverter.getDefaultValue(this.defaultNBTId)
: NBTValueConverter.mapNBTToValue(extractedNBT);
return this.getVariableUsingValue(value);
}

@Nullable
@SuppressWarnings( {"rawtypes", "unchecked"})
private ItemStack getVariableUsingValue(IValue value) {
IVariableFacadeHandlerRegistry registry = IntegratedDynamics._instance.getRegistryManager()
.getRegistry(IVariableFacadeHandlerRegistry.class);
NBTBase extractedNBT = this.extractionPath.extract(this.lastEvaluatedNBT);
if (value == null) {
return null;
}
Expand All @@ -599,24 +635,6 @@ public IValueTypeVariableFacade create(int id) {
);
}

@Nullable
private ItemStack getVariableByValueMode() {
this.refreshVariables(true);
NBTBase extractedNBT = this.extractionPath.extract(this.lastEvaluatedNBT);
IValue value = extractedNBT == null
? NBTValueConverter.getDefaultValue(this.defaultNBTId)
: NBTValueConverter.mapNBTToValue(extractedNBT);
return this.getVariableUsingValue(value);
}

@Nullable
private ItemStack getVariableByOperatorMode() {
return this.getVariableUsingValue(ValueOperator.of(new NBTExtractionOperator(
this.extractionPath,
this.defaultNBTId
)));
}

@Override
@Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
Expand Down

0 comments on commit f46f32c

Please sign in to comment.