Skip to content

Commit

Permalink
Misc Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Sep 13, 2024
1 parent dd75f7e commit 337ae98
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.direwolf20.justdirethings.common.blockentities.basebe.RedstoneControlledBE;
import com.direwolf20.justdirethings.setup.Registration;
import com.direwolf20.justdirethings.util.ExperienceUtils;
import com.direwolf20.justdirethings.util.MiscHelpers;
import com.direwolf20.justdirethings.util.interfacehelpers.AreaAffectingData;
import com.direwolf20.justdirethings.util.interfacehelpers.FilterData;
import com.direwolf20.justdirethings.util.interfacehelpers.RedstoneControlData;
Expand All @@ -28,8 +29,8 @@

public class ExperienceHolderBE extends BaseMachineBE implements AreaAffectingBE, RedstoneControlledBE {
public FilterData filterData = new FilterData();
public AreaAffectingData areaAffectingData = new AreaAffectingData();
public RedstoneControlData redstoneControlData = new RedstoneControlData();
public AreaAffectingData areaAffectingData = new AreaAffectingData(getBlockState().getValue(BlockStateProperties.FACING).getOpposite());
public RedstoneControlData redstoneControlData = getDefaultRedstoneData();
public int exp;
public int targetExp;
private Player currentPlayer;
Expand Down Expand Up @@ -78,12 +79,16 @@ public void storeExp(Player player, int levelChange) {
int expRemoved = ExperienceUtils.removePoints(player, expInCurrentLevel);
this.exp += expRemoved;
levelChange--; // We've already removed part of a level
if (player.experienceProgress > 0.0f && player.experienceProgress < 0.01f)
player.experienceProgress = 0f;
}

if (levelChange > 0) {
// Now remove the specified number of full levels
int expRemoved = ExperienceUtils.removeLevels(player, levelChange);
this.exp += expRemoved;
if (player.experienceProgress > 0.0f && player.experienceProgress < 0.01f)
player.experienceProgress = 0f;
}
}

Expand Down Expand Up @@ -168,7 +173,7 @@ private void handleExperience() {
doParticles(new ItemStack(Items.EXPERIENCE_BOTTLE), currentPlayer.getEyePosition().subtract(0, 0.25f, 0), false);
if (exp == 0)
currentPlayer = null; //Clear current target if we run out of exp
} else if (currentLevel > targetExp || currentPlayer.experienceProgress > 0.001f) {
} else if (currentLevel > targetExp || currentPlayer.experienceProgress > 0.01f) {
storeExp(currentPlayer, 1);
doParticles(new ItemStack(Items.EXPERIENCE_BOTTLE), currentPlayer.getEyePosition().subtract(0, 0.25f, 0), true);
} else
Expand Down Expand Up @@ -207,7 +212,7 @@ private void findTargetPlayer() {
for (Player player : entityList) {
if (ownerOnly && !player.getUUID().equals(placedByUUID))
continue;
if (player.experienceLevel != targetExp || player.experienceProgress != 0.0f) {
if (player.experienceLevel != targetExp || player.experienceProgress > 0.01f) {
this.currentPlayer = player;
return;
}
Expand All @@ -231,4 +236,29 @@ public void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) {
collectExp = tag.getBoolean("collectExp");
ownerOnly = tag.getBoolean("ownerOnly");
}

@Override
public AreaAffectingData getDefaultAreaData(AreaAffectingBE areaAffectingBE) {
return areaAffectingBE.getDefaultAreaData(getBlockState().getValue(BlockStateProperties.FACING).getOpposite());
}

@Override
public RedstoneControlData getDefaultRedstoneData() {
return new RedstoneControlData(MiscHelpers.RedstoneMode.PULSE);
}

@Override
public boolean isDefaultSettings() {
if (!super.isDefaultSettings())
return false;
if (exp != 0)
return false;
if (targetExp != 0)
return false;
if (collectExp)
return false;
if (ownerOnly)
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class ItemCollectorBE extends BaseMachineBE implements FilterableBE, AreaAffectingBE, RedstoneControlledBE {
protected BlockCapabilityCache<IItemHandler, Direction> attachedInventory;
public FilterData filterData = new FilterData();
public AreaAffectingData areaAffectingData = new AreaAffectingData();
public AreaAffectingData areaAffectingData = new AreaAffectingData(getBlockState().getValue(BlockStateProperties.FACING).getOpposite());
public RedstoneControlData redstoneControlData = new RedstoneControlData();

public ItemCollectorBE(BlockPos pPos, BlockState pBlockState) {
Expand Down Expand Up @@ -126,4 +126,9 @@ private IItemHandler getAttachedInventory() {
}
return attachedInventory.getCapability();
}

@Override
public AreaAffectingData getDefaultAreaData(AreaAffectingBE areaAffectingBE) {
return areaAffectingBE.getDefaultAreaData(getBlockState().getValue(BlockStateProperties.FACING).getOpposite());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.direwolf20.justdirethings.setup.Registration;
import com.direwolf20.justdirethings.util.MiscHelpers;
import com.direwolf20.justdirethings.util.UsefulFakePlayer;
import com.direwolf20.justdirethings.util.interfacehelpers.AreaAffectingData;
import com.direwolf20.justdirethings.util.interfacehelpers.FilterData;
import com.direwolf20.justdirethings.util.interfacehelpers.RedstoneControlData;
import com.mojang.authlib.GameProfile;
Expand Down Expand Up @@ -211,12 +212,16 @@ public RedstoneControlData getDefaultRedstoneData() {
return new RedstoneControlData();
}

public AreaAffectingData getDefaultAreaData(AreaAffectingBE areaAffectingBE) {
return areaAffectingBE.getDefaultAreaData(getBlockState().getValue(BlockStateProperties.FACING));
}

public boolean isDefaultSettings() {
if (tickSpeed != 20)
return false;
if (direction != 0)
return false;
if (this instanceof AreaAffectingBE areaAffectingBE && !areaAffectingBE.getAreaAffectingData().equals(areaAffectingBE.getDefaultAreaData(getBlockState().getValue(BlockStateProperties.FACING))))
if (this instanceof AreaAffectingBE areaAffectingBE && !areaAffectingBE.getAreaAffectingData().equals(getDefaultAreaData(areaAffectingBE)))
return false;
if (this instanceof FilterableBE filterableBE && !filterableBE.getFilterData().equals(getDefaultFilterData()))
return false;
Expand Down

0 comments on commit 337ae98

Please sign in to comment.